builder icon indicating copy to clipboard operation
builder copied to clipboard

Nuxt3 - isolated-vm issue on Vercel

Open 20x-dz opened this issue 1 year ago • 7 comments

Describe the bug Following the latest release ([email protected]) with #3560, I immediately installed the latest version to see if #3288 was indeed fixed.

To Reproduce Steps to reproduce the behavior:

  1. Deploy to vercel through a github CI/CD pipeline (on ubuntu-latest with node: 20 and nitro's vercel preset)
  2. visit the preview url after deployment
  3. See the following error in the logs:
Unhandled Rejection: Error: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /var/task/node_modules/isolated-vm/out/isolated_vm.node)
    at Module._extensions..node (node:internal/modules/cjs/loader:1586:18)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12)
    at /opt/rust/nodejs.js:1:11708
    at Function.dr (/opt/rust/nodejs.js:1:12082)
    at e.<computed>.oe._load (/opt/rust/nodejs.js:1:11678)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/var/task/node_modules/isolated-vm/isolated-vm.js:1:18)
    at Module._compile (node:internal/modules/cjs/loader:1469:14) {
  code: 'ERR_DLOPEN_FAILED'
}
Unhandled Rejection: Error: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.30' not found (required by /var/task/node_modules/isolated-vm/out/isolated_vm.node)
    at Module._extensions..node (node:internal/modules/cjs/loader:1586:18)
    at Module.load (node:internal/modules/cjs/loader:1288:32)
    at Module._load (node:internal/modules/cjs/loader:1104:12)
    at /opt/rust/nodejs.js:1:11708
    at Function.dr (/opt/rust/nodejs.js:1:12082)
    at e.<computed>.oe._load (/opt/rust/nodejs.js:1:11678)
    at Module.require (node:internal/modules/cjs/loader:1311:19)
    at require (node:internal/modules/helpers:179:18)
    at Object.<anonymous> (/var/task/node_modules/isolated-vm/isolated-vm.js:1:18)
    at Module._compile (node:internal/modules/cjs/loader:1469:14) {
  code: 'ERR_DLOPEN_FAILED'
}
Node.js process exited with exit status: 128. The logs above can help with debugging the issue.

Expected behavior See the rendered page.

Screenshots image

Additional context Only the module was added to nuxt.config.ts:

diff --git a/frontend/nuxt.config.ts b/frontend/nuxt.config.ts
index 0f0bd96c..9db6641e 100644
--- a/frontend/nuxt.config.ts
+++ b/frontend/nuxt.config.ts
@@ -190,7 +190,13 @@ export default defineNuxtConfig({
     },
   },
   modules: [
-    "@builder.io/sdk-vue/nuxt",
+    [
+      "@builder.io/sdk-vue/nuxt",
+      {
+        includeCompiledCss: true, // Includes Builder.io CSS (default: true)
+        initializeNodeRuntime: true, // Initializes isolated VM in Node runtime (default: false)
+      },
+    ],
     "nuxt-svgo",
     "@nuxt/image",
     "@nuxtjs/tailwindcss",

Loosely related to #3604

20x-dz avatar Oct 04 '24 17:10 20x-dz

Hello @20x-dz, thanks for the quick feedback. I was trying to reproduce this and I tweaked my nuxt.config.ts like this to use the vercel preset and it was able to build and deploy.

// https://nuxt.com/docs/api/configuration/nuxt-config
export default defineNuxtConfig({
  compatibilityDate: "2024-04-03",
  devtools: { enabled: true },
  nitro: {
    preset: "vercel",
  },
  modules: [
    [
      "@builder.io/sdk-vue/nuxt",
      {
        includeCompiledCss: true,
        initializeNodeRuntime: true,
      },
    ],
  ],
});

Repo:https://github.com/sidmohanty11/nuxt-isolated-vm2 hosted: https://nuxt-isolated-vm2.vercel.app/

Could you please check if I am missing any step to reproduce this bug?

sidmohanty11 avatar Oct 08 '24 11:10 sidmohanty11

@sidmohanty11 Interesting. How do you build and deploy? We run the build on a github CI/CD pipeline (node20, ubuntu-latest) and deploy the output from there.

20x-dz avatar Oct 09 '24 08:10 20x-dz

@20x-dz I just imported the project as a new project in Vercel (uses node v20). Could you please share an example workflow file that I can follow for the CI/CD pipeline?

sidmohanty11 avatar Oct 09 '24 08:10 sidmohanty11

@sidmohanty11 https://gist.github.com/20x-dz/f55422a4bd652d293aa24ce79c4f3165 (I hope I didn't clean up too much, but that should do it). It's basically from the official documentation with some adjustments (tests, output, etc.): https://vercel.com/guides/how-can-i-use-github-actions-with-vercel

20x-dz avatar Oct 09 '24 09:10 20x-dz

@20x-dz thank you so much! It was very helpful, I was able to reproduce this issue. We're actively searching for a solution for this; I'll keep you updated as soon as we find one.

sidmohanty11 avatar Oct 09 '24 13:10 sidmohanty11

Great! 🤞

I contacted Vercel support as well, although I think they might not have understood the problem. Anyway, here's their current statement, maybe it helps?

The required dependency may have been missed by the build step, there is a mechanism by which these can be included manually which would be our recommended means to attempt to resolve this issue.

https://vercel.com/docs/projects/project-configuration#functions

First, create or modify your vercel.json file in the root of your project. Add the functions property to specify configurations for your functions. For each function that needs additional files, add an includeFiles property. An example entry can be seen below for reference on the structure.

{
  "functions": {
    "api/myFunction.js": {
      "includeFiles": ["data/**", "config/*.json"]
    }
  }
}

This will ensure that the dependency is included which may resolve the issue that you are facing.

20x-dz avatar Oct 09 '24 18:10 20x-dz

Hello @20x-dz, it appears that the GLIBCXX library is missing from the ubuntu-latest image used by Vercel. This library is required by the isolated-vm library to compile. As an interim solution, we suggest manually installing the libstdc++6 library in your workflow YAML file which should fix this issue.

Repo: https://github.com/sidmohanty11/nuxt-isolated-vm2 YAML: https://github.com/sidmohanty11/nuxt-isolated-vm2/blob/main/.github/workflows/deploy.yml Hosted: https://nuxt-isolated-vm2.vercel.app/

name: Vercel Production Deployment
env:
  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
  push:
    branches:
      - main
jobs:
  Deploy-Production:
    runs-on: ubuntu-latest
    # have to convert to container to install glibcxx
    container:
      image: node:20
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4

      # install glibcxx as isolated vm depends on it
      - name: Install Dependencies for GLIBCXX
        run: |
          apt-get update && \
          apt-get install -y build-essential libstdc++6

      - name: Install Project Dependencies
        run: npm install

      - name: Install Vercel CLI
        run: npm install --global vercel@latest

      - name: Pull Vercel Environment Information
        run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}

      - name: Build Project Artifacts
        run: vercel build --token=${{ secrets.VERCEL_TOKEN }}

      - name: Deploy Project Artifacts to Vercel
        run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}

Meanwhile, we are working on adding better error handling and providing helpful warnings wherever possible for this issue.

sidmohanty11 avatar Oct 10 '24 10:10 sidmohanty11

@20x-dz we noticed that the above solution doesn't work as expected. We do need the dependencies but they are not being linked correctly resulting in the same error.

As of now there are two ways to fix this:

  • as per https://vercel.com/docs/build-output-api/v3#known-limitations, the machine you build the project on must have the same OS as the one you deploy to. We recommend not prebuilding your project if it contains the Builder SDK, because the SDK depends on isolated-vm which will be generated differently depending on the OS. If you move the build step to the vercel server, the error goes away: https://github.com/sidmohanty11/nuxt-isolated-vm2/actions/runs/11437610807/job/31817464700 example workflow looks like,
name: Vercel Production Deployment
env:
  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
  push:
    branches:
      - main
jobs:
  Deploy-Production:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4

      - name: Use Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Install Project Dependencies
        run: npm install

      - name: Install Vercel CLI
        run: npm install --global vercel@latest

      - name: Pull Vercel Environment Information
        run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}

      - name: Deploy Project Artifacts to Vercel
        run: |
          vercel deploy --prod --token=${{ secrets.VERCEL_TOKEN }}

  • alternatively, we have found that ubuntu 20.04 works with our native dependency. See the updated job here: https://github.com/sidmohanty11/nuxt-isolated-vm2/actions/runs/11438300107/job/31819603330
name: Vercel Production Deployment
env:
  VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
  VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
on:
  push:
    branches:
      - main
jobs:
  Deploy-Production:
    runs-on: ubuntu-20.04
    steps:
      - name: Checkout Code
        uses: actions/checkout@v4

      - name: Use Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 20

      - name: Install Project Dependencies
        run: npm install

      - name: Install Vercel CLI
        run: npm install --global vercel@latest

      - name: Pull Vercel Environment Information
        run: vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}

      - name: Build Project Artifacts
        run: vercel build --token=${{ secrets.VERCEL_TOKEN }}

      - name: Deploy Project Artifacts to Vercel
        run: |
          vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}

sidmohanty11 avatar Oct 21 '24 13:10 sidmohanty11

@sidmohanty11 Super nice of you to follow up with a solution, because I was playing around a week ago and it not even didn't work (and I had no time to dig deeper into it), the resulting builds crashed the vercel dashboard as well. 🙈

I'll try this and get back to you.

20x-dz avatar Oct 21 '24 14:10 20x-dz

We are marking this issue as closed given that we have provided a working solution that was tested in a Nuxt + Vercel environment.

Feel free to reopen if you are still facing any issues

samijaber avatar Oct 30 '24 14:10 samijaber

Does the solution require any user facing changes (eg any update to code needed), or will just work on latest sdk version?

On Wed, Oct 30 2024 at 7:06 AM, Sami Jaber < @.*** > wrote:

We are marking this issue as closed given that we have provided a working solution that was tested in a Nuxt + Vercel environment.

Feel free to reopen if you are still facing any issues

— Reply to this email directly, view it on GitHub ( https://github.com/BuilderIO/builder/issues/3605#issuecomment-2447286414 ) , or unsubscribe ( https://github.com/notifications/unsubscribe-auth/AAGOEA6UTAY3YSZWNEUXN23Z6DRYDAVCNFSM6AAAAABPMJ2TAWVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINBXGI4DMNBRGQ ). You are receiving this because you are subscribed to this thread. Message ID: <BuilderIO/builder/issues/3605/2447286414 @ github. com>

steve8708 avatar Oct 30 '24 14:10 steve8708

@steve8708 the issue is regarding a mismatch between the build and deploy environments (they have to be the same so that native dependencies like isolated-vm can be built and then run correctly). The solution is therefore purely on the user-end, in their build/deploy pipeline.

samijaber avatar Oct 30 '24 15:10 samijaber

so tl;dr nothing for users to do, will just work on latest version?

steve8708 avatar Oct 30 '24 16:10 steve8708

No, the user will need to do something.

IF a user builds their app on one platform and deploys it on another platform (like using vercel deploy --prebuilt on GitHub CI) then they will need to either:

  • stop doing that, and build the app on vercel itself (instead of on their CI)
  • OR point to a specific ubuntu version in GitHub CI so that the app builds correctly

To re-iterate, this is only a (potential) issue when apps are built outside of their deployment environment. Most customers will not face this issue and will need to do nothing.

samijaber avatar Oct 30 '24 16:10 samijaber

@sidmohanty11 @samijaber

I just found some time to update our workflows, building it on vercel instead of in the CI works (which seems kind of obvious in retrospect 🙈 ). Thank you both so much for your support and the solutions provided! You rock! 💪

20x-dz avatar Nov 05 '24 08:11 20x-dz