nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
107.61k stars 29.59k forks source link

node-gyp failing when trying to install ffi-napi #49737

Closed s0ckz closed 1 year ago

s0ckz commented 1 year ago

Version

v18.18.0

Platform

Docker with node:18.18-buster-slim image

Subsystem

No response

What steps will reproduce the bug?

docker run -it node:18.18-buster-slim bash
# inside the container
apt update && apt install -y python3 build-essential && yarn add ffi-napi@^4.0.3

How often does it reproduce? Is there a required condition?

10/10

What is the expected behavior? Why is that the expected behavior?

It's expected that ffi-napi is installed. It works on 18.17:

yarn add v1.22.19
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 6 new dependencies.
info Direct dependencies
└─ ffi-napi@4.0.3
info All dependencies
├─ ffi-napi@4.0.3
├─ get-symbol-from-current-process-h@1.0.2
├─ get-uv-event-loop-napi-h@1.0.6
├─ ms@2.1.2
├─ ref-napi@3.0.3
└─ ref-struct-di@1.1.1
Done in 9.54s.

What do you see instead?

yarn add v1.22.19
info No lockfile found.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
[2/2] ⠄ ffi-napi
error /node_modules/ffi-napi: Command failed.
Exit code: 1
Command: node-gyp-build
Arguments:
Directory: /node_modules/ffi-napi
Output:
node:events:495
      throw er; // Unhandled 'error' event
      ^

Error: spawn node-gyp ENOENT
    at ChildProcess._handle.onexit (node:internal/child_process:284:19)
    at onErrorNT (node:internal/child_process:477:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
Emitted 'error' event on ChildProcess instance at:
    at ChildProcess._handle.onexit (node:internal/child_process:290:12)
    at onErrorNT (node:internal/child_process:477:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'spawn node-gyp',
  path: 'node-gyp',
  spawnargs: [ 'rebuild' ]
}

Additional information

It might be related to https://github.com/nodejs/node/issues/48444

evitree commented 1 year ago

+1 to this issue, all our CI/CD pipelines failed ysterday with Docker Node 18 LTS (resolving to 18.18) with a similar error and we had to revert to Node 18.17 to make things work again. To be more precise, running on circle image (cimg:node18-lts) and node:18-slim.

info This package requires node-gyp, which is not currently installed. Yarn will attempt to automatically install it. If this fails, you can run "yarn global add node-gyp" to manually install it.
error An unexpected error occurred: "/home/circleci/project/node_modules/web3: Cannot read properties of undefined (reading 'config')".
info If you think this is a bug, please open a bug report with the information provided in "/home/circleci/.config/yarn/global/yarn-error.log".
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.
[1/4] Resolving packages...
[2/4] Fetching packages...
[3/4] Linking dependencies...
[4/4] Building fresh packages...
success Installed "node-gyp@9.4.0" with binaries:
      - node-gyp

Exited with code exit status 1

Unclear if it's related to the above, if not let me know and I'll write a more extensive ticket across our CircleCI errors + docker CI/CD pipeline with more logs.

For now pinning both back to 18.17 fixed it.

bnoordhuis commented 1 year ago

It might be related to https://github.com/nodejs/node/issues/48444

Probably not because the kernel in buster is too old. Libuv uses io_uring when approx. the kernel >= 5.13.

robertkowalski commented 1 year ago

we run into the same issue with docker and debian:testing images and we also see it with latest node 20

diogotorres97 commented 1 year ago

Same here 👍

          yarn global add node-gyp && yarn install --frozen-lockfile

This workaround seems to be less flaky, I don't want to pin to a minor version because of security updates

bnoordhuis commented 1 year ago

v18.18.0 contains an npm upgrade from v9.7.1 to v9.7.2 (commit 4a6177daad59ec5bb4c29f10822d5a98655efe1a) that removes deps/npm/bin/node-gyp-bin/node-gyp. It seems highly probable that change is responsible.

Try downgrading npm and, if that resolves the issue, close this bug report and report it over at npm.

BenAkroyd commented 1 year ago

~Seems like npm 9.7.2 still has node-gyp, unless I'm missing something: https://github.com/npm/cli/tree/v9.7.2/node_modules/%40npmcli/node-gyp~

Whoops, in bin not the module itself. Yup, confirmed that was absent there.

Explicitly using npm 9.7.1 did resolve the issue for me (I was experiencing a similar issue using npm 9.8.1 myself)

bnoordhuis commented 1 year ago

I see you've reported an npm bug so I'll go ahead and close this one. We just need to wait for npm to send the bug fix our way.

hackinghacker1 commented 3 weeks ago

everyones actually fucking retarded wheres the answer dumbasses