nuxt / vercel-builder

Vercel Builder for Nuxt
MIT License
646 stars 75 forks source link

Error building bcrypt with node-gyp #371

Open vicmars5 opened 3 years ago

vicmars5 commented 3 years ago

I started to have this issues with nuxt/vercel-builder 0.17.12.

[4/5] Building fresh packages...
--
13:29:39.104 | error /vercel/workpath1/node_modules/bcrypt: Command failed.
13:29:39.104 | Exit code: 127
13:29:39.104 | Command: node-pre-gyp install --fallback-to-build
13:29:39.104 | Arguments:
13:29:39.104 | Directory: /vercel/workpath1/node_modules/bcrypt
13:29:39.104 | Output:
13:29:39.104 | /bin/sh: node-pre-gyp: command not found
13:29:39.105 | info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
13:29:40.019 | Error: Command "yarn install" exited with 127
13:29:42.852 | Done with "nuxt.config.js"

Seems, for some reason the bcrypt installation started to fail after version 0.17.7. I made a test today using this version, and the project builded successfully.

P4sca1 commented 3 years ago

I have the same issue. I think its because node-gyp requires python to be installed. Maybe @nuxt/verceul-builder could install python? https://vercel.com/docs/build-step#build-image

P4sca1 commented 3 years ago

For me the problem is that @nuxt/vercel-builder tries to install all the dependencies in my monorepo and not only those needed for my nuxt project. Something like yarn --focus could work: https://classic.yarnpkg.com/blog/2018/05/18/focused-workspaces/

danielroe commented 3 years ago

@P4sca1 have you tried configuring focus using .yarnrc? Yarn should pick up that preference when installing dependencies for your Nuxt runtime.

P4sca1 commented 3 years ago

I will try that and leave a response here within the next 2 hours.

P4sca1 commented 3 years ago

Focused installs do not work for me. Yarn tries to install packages in my workspace from a registry that are not published to any registry (private packages).

danielroe commented 3 years ago

@P4sca1 presumably that's true on your local machine as well?

P4sca1 commented 3 years ago

Yes, it is.

danielroe commented 3 years ago

@P4sca1 It may be that yarn v2 (when we support it on vercel-builder) solves the focus issue for us.

P4sca1 commented 3 years ago

@danielroe In a monorepo, the best way would be to only install dependencies of the nuxt app, but yarn unfortunately doesn't have such a feature. I thought focused installs do just that, but they are not: https://github.com/yarnpkg/yarn/issues/6715 https://github.com/yarnpkg/yarn/issues/5864#issuecomment-419948958

So it seems like we have to install all dependencies so python is required in the build image to support node-gyp.

The problem is that the node_modules folder might get way too big because it inclues packages not required to run the nuxt app. An alternative that I use in my Dockerfile is to only copy those packages that are required for the build of the nuxt app. So for example if you have the following monorepo structure:

/apps/
  - frontend/ (depends on package-1)
  - api/ (depends on package-1 and package-2)
  - daemon/ (depends on package-2)
/packages/
  - package-1/
  - package-2/

If you want to build the frontend you only copy /apps/frontend and /packages/package-1. Then yarn install --frozen-lockfile only installs packages required by the frontend or its dependencies and not for example bcrypt which is required by api.

Because there is no way to exclude folders in vercel, this builder could be configurable to delete specific folders before running npm / yarn install.

P4sca1 commented 3 years ago

@P4sca1 It may be that yarn v2 (when we support it on vercel-builder) solves the focus issue for us.

Nuxt 2 does (and afaik will not) support yarn 2. Nuxt 3 will support it, but nuxt 3 comes with serverless support out of the box. At least that's what I have read.

P4sca1 commented 3 years ago

It seems like nuxt 2 can support yarn 2 when disabling PNP. One could then try focused workspace installs in yarn 2: https://yarnpkg.com/cli/workspaces/focus

danielroe commented 3 years ago

@P4sca1

P4sca1 commented 3 years ago

I thought .vercelignore is applied after building and not before. I will try out .vercelignore as it could be the solution to the problem. Thanks for the hint!

P4sca1 commented 3 years ago

.vercelignore seems to be only for "what files to exclude when uploading" and not "what files to exclude when building". So it still tries to install bcrypt which errors.

thirdman commented 3 years ago

Any solution to this?

kylewelsby commented 3 years ago

I've spent all night trying to find a solution to this, Sadly I can not inject yarn global add node-gyp before the builder starts.

Unless I am missing something.

kylewelsby commented 3 years ago

I think I found a workaround to the resolve this issue.

You can add vercel-build to your package.json to global install node-gyp, you'll need to add a builds step before @nuxtjs/vercel-builder to ensure it gets installed in the correct order.

// vercel.json
{
  "version": 2,
  "builds": [
    {
      "src": "package.json",
      "use": "@vercel/node"
    },
    {
      "src": "nuxt.config.js",
      "use": "@nuxtjs/vercel-builder",
      "config": {
        "serverFiles": ["server-middleware/**"]
      }
    }
  ],
}
// package.json
{
  "scripts": {
    "vercel-build": "yarn global add node-gyp"
  }
}
kevcodez commented 3 years ago

Also running into this even though I am not using any dependency that requires node-gyp.

22:39:36.454 [log] Running nuxt build --standalone --no-lock --config-file "nuxt.config.js" /vercel/workpath0
22:40:26.215 [info] Nuxt build took: 49952.562688 ms
22:40:26.215 [log] ----------------- Install dependencies -----------------
22:40:26.490 yarn install v1.22.10
22:40:26.584 [1/5] Resolving packages...
22:40:26.901 [2/5] Fetching packages...
22:40:31.323 [3/5] Linking dependencies...
22:40:31.323 warning " > @nuxtjs/composition-api@0.23.2" has unmet peer dependency "@nuxt/vue-app@^2.15".
22:40:31.323 warning " > @nuxtjs/composition-api@0.23.2" has unmet peer dependency "fs-extra@^8.1.0".
22:40:31.323 warning " > @nuxtjs/composition-api@0.23.2" has unmet peer dependency "nuxt@^2.15".
22:40:31.323 warning " > @nuxtjs/composition-api@0.23.2" has unmet peer dependency "vue@^2".
22:40:31.323 warning "@nuxtjs/composition-api > @vue/composition-api@1.0.0-rc.7" has unmet peer dependency "vue@>= 2.5 < 3".
22:40:31.323 warning " > @tailwindcss/typography@0.4.0" has unmet peer dependency "tailwindcss@2.0.0-alpha.24 || ^2.0.0".
22:40:33.082 [4/5] Building fresh packages...
22:40:33.192 error /vercel/workpath0/node_modules/bufferutil: Command failed.
22:40:33.192 Exit code: 127
22:40:33.193 Command: node-gyp-build
22:40:33.193 Arguments:
22:40:33.193 Directory: /vercel/workpath0/node_modules/bufferutil
22:40:33.193 Output:
22:40:33.193 /bin/sh: node-gyp-build: command not found
22:40:33.193 info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
22:40:33.257 Error: Command "yarn install" exited with 127
22:40:35.917 Done with "nuxt.config.js"
22:40:36.477 Build completed. Populating build cache...
22:40:39.168 Uploading build cache [3.47 MB]...
22:40:39.302 Build cache uploaded: 133.928ms
22:40:39.518 Done with "package.json"

@kylewelsby your suggestion didn't work for me, anything else you configured?

morgan4080 commented 3 years ago

error /vercel/path3/node_modules/bcrypt: Command failed.

09:45:01.244 | Exit code: 127 09:45:01.244 | Command: node-pre-gyp install --fallback-to-build 09:45:01.244 | Arguments: 09:45:01.244 | Directory: /vercel/path3/node_modules/bcrypt 09:45:01.244 | Output: 09:45:01.244 | /bin/sh: node-pre-gyp: command not found 09:45:01.244 | info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command. 09:45:02.288 | Error: Command "yarn install" exited with 127 09:45:03.969 | Build completed. Populating build cache...

Kindly someone provide a solution to the node-pre-gyp issue

creazy231 commented 3 years ago

/bin/sh: node-pre-gyp: command not found is still a problem

inbytesdevteam commented 3 years ago

I added in an update to a similar issue I faced in #468 -- I used npm instead of yarn and it worked (and I'm not sure why)

mahapo commented 2 years ago

Same issue:

00:36:40.971 | [4/5] Building fresh packages...
-- | --
00:36:42.356 | error /vercel/path1/node_modules/leveldown: Command failed.
00:36:42.356 | Exit code: 127
00:36:42.357 | Command: node-gyp-build
00:36:42.357 | Arguments:
00:36:42.357 | Directory: /vercel/path1/node_modules/leveldown
00:36:42.357 | Output:
00:36:42.357 | /bin/sh: node-gyp-build: command not found
00:36:42.358 | info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
00:36:47.843 | Error: Command "yarn install" exited with 127
florian-lefebvre commented 2 years ago

I think I found a workaround to the resolve this issue.

You can add vercel-build to your package.json to global install node-gyp, you'll need to add a builds step before @nuxtjs/vercel-builder to ensure it gets installed in the correct order.

// vercel.json
{
  "version": 2,
  "builds": [
    {
      "src": "package.json",
      "use": "@vercel/node"
    },
    {
      "src": "nuxt.config.js",
      "use": "@nuxtjs/vercel-builder",
      "config": {
        "serverFiles": ["server-middleware/**"]
      }
    }
  ],
}
// package.json
{
  "scripts": {
    "vercel-build": "yarn global add node-gyp"
  }
}

It worked for me! I'm using the @supabase/supabase-js package that relies on node-gyp-build so my vercel-build command looks like yarn global add node-gyp-build.

jordienr commented 2 years ago

For me the solution to add the pre build step doesn't work. Wish we could get an answer from Nuxt or Vercel.

Ic3m4n34 commented 2 years ago

For me the solution to add the pre build step doesn't work. Wish we could get an answer from Nuxt or Vercel.

yeah. Me too!

xiaotiandada commented 2 years ago

I think I found a workaround to the resolve this issue. You can add vercel-build to your package.json to global install node-gyp, you'll need to add a builds step before @nuxtjs/vercel-builder to ensure it gets installed in the correct order.

// vercel.json
{
  "version": 2,
  "builds": [
    {
      "src": "package.json",
      "use": "@vercel/node"
    },
    {
      "src": "nuxt.config.js",
      "use": "@nuxtjs/vercel-builder",
      "config": {
        "serverFiles": ["server-middleware/**"]
      }
    }
  ],
}
// package.json
{
  "scripts": {
    "vercel-build": "yarn global add node-gyp"
  }
}

It worked for me! I'm using the @supabase/supabase-js package that relies on node-gyp-build so my vercel-build command looks like yarn global add node-gyp-build.

https://github.com/xiaotiandada/blog/issues/89 work

simonigreen commented 2 years ago

I think I found a workaround to the resolve this issue. You can add vercel-build to your package.json to global install node-gyp, you'll need to add a builds step before @nuxtjs/vercel-builder to ensure it gets installed in the correct order.

// vercel.json
{
  "version": 2,
  "builds": [
    {
      "src": "package.json",
      "use": "@vercel/node"
    },
    {
      "src": "nuxt.config.js",
      "use": "@nuxtjs/vercel-builder",
      "config": {
        "serverFiles": ["server-middleware/**"]
      }
    }
  ],
}
// package.json
{
  "scripts": {
    "vercel-build": "yarn global add node-gyp"
  }
}

It worked for me! I'm using the @supabase/supabase-js package that relies on node-gyp-build so my vercel-build command looks like yarn global add node-gyp-build.

I'm also using Supabase but in my case via https://github.com/supabase-community/nuxt-supabase

I had to go with "vercel-build": "yarn global add node-gyp-build" in package.json as well to successfully deploy.

mrinalwahal commented 2 years ago

Hey everyone,

I'm trying to deploy a Nuxt SSR app on Vercel. And facing the same issue.

But @florian-lefebvre's this approach is definitely not working for me.

Any other solutions @danielroe?

Ic3m4n34 commented 1 year ago

@mrinalwahal Same here. Did you find a solution?

floki1250 commented 1 year ago

@mrinalwahal @Ic3m4n34 it works, Actually.

Package.json

"scripts": { "dev": "nuxt", "build": "nuxt build", "start": "nuxt start", "generate": "nuxt generate", "vercel-build": "yarn global add node-gyp-build" },

Vercel.json { "version": 2, "builds": [ { "src": "package.json", "use": "@vercel/node" }, { "src": "nuxt.config.js", "use": "@nuxtjs/vercel-builder", "config": { "serverFiles": [ "package.json" ] } } ], "routes": [ { "src": "/sw.js", "continue": true, "headers": { "Cache-Control": "public, max-age=0, must-revalidate", "Service-Worker-Allowed": "/" } } ] }

mrinalwahal commented 1 year ago

@mrinalwahal @Ic3m4n34 it works, Actually.

Package.json

"scripts": { "dev": "nuxt", "build": "nuxt build", "start": "nuxt start", "generate": "nuxt generate", "vercel-build": "yarn global add node-gyp-build" },

Vercel.json { "version": 2, "builds": [ { "src": "package.json", "use": "@vercel/node" }, { "src": "nuxt.config.js", "use": "@nuxtjs/vercel-builder", "config": { "serverFiles": [ "package.json" ] } } ], "routes": [ { "src": "/sw.js", "continue": true, "headers": { "Cache-Control": "public, max-age=0, must-revalidate", "Service-Worker-Allowed": "/" } } ] }

It worked for me as well :)

Turns out, I hadn't added the build command properly.

Thanks!