node-gyp-build icon indicating copy to clipboard operation
node-gyp-build copied to clipboard

Build fails when using `--no-bin-links`

Open JamesXNelson opened this issue 1 year ago • 4 comments

Hi there.

We have a private enterprise repo where we have to use --no-bin-links due to how our CI caching layer works (bin links can lead to hanging symlinks that blow up on us).

When running npm i, everything is happy. Adding --no-bin-links, and we get traces like so:

6299 verbose reify failed optional dependency /dh/ws2/iris/web/client-ui/node_modules/msgpackr-extract
6300 silly reify mark deleted [
6300 silly reify   '/dh/ws2/iris/web/client-ui/node_modules/msgpackr-extract',
6300 silly reify   '/dh/ws2/iris/web/client-ui/node_modules/.bin/download-msgpackr-prebuilds'
6300 silly reify ]
6301 verbose reify failed optional dependency /dh/ws2/iris/web/client-ui/node_modules/node-gyp-build-optional-packages
6302 silly reify mark deleted [
6302 silly reify   '/dh/ws2/iris/web/client-ui/node_modules/node-gyp-build-optional-packages',
6302 silly reify   '/dh/ws2/iris/web/client-ui/node_modules/.bin/node-gyp-build-optional-packages',
6302 silly reify   '/dh/ws2/iris/web/client-ui/node_modules/.bin/node-gyp-build-optional-packages-optional',
6302 silly reify   '/dh/ws2/iris/web/client-ui/node_modules/.bin/node-gyp-build-optional-packages-test'
6302 silly reify ]
6303 verbose reify failed optional dependency /dh/ws2/iris/web/client-ui/node_modules/node-gyp-build-optional-packages/node_modules/detect-libc
6304 silly reify mark deleted [
6304 silly reify   '/dh/ws2/iris/web/client-ui/node_modules/node-gyp-build-optional-packages/node_modules/detect-libc'
6304 silly reify ]
6305 timing build:run:install:node_modules/msgpackr-extract Completed in 36ms
6306 info run [email protected] install { code: 127, signal: null }
6307 timing reify:rollback:createSparse Completed in 1144ms
6308 timing reify:rollback:retireShallow Completed in 0ms
6309 timing command:i Completed in 28387ms
6310 verbose stack Error: command failed
6310 verbose stack     at ChildProcess.<anonymous> (/home/james/.nvm/versions/node/v20.13.1/lib/node_modules/npm/node_modules/@npmcli/promise-spawn/lib/index.js:53:27)
6310 verbose stack     at ChildProcess.emit (node:events:519:28)
6310 verbose stack     at maybeClose (node:internal/child_process:1105:16)
6310 verbose stack     at Socket.<anonymous> (node:internal/child_process:457:11)
6310 verbose stack     at Socket.emit (node:events:519:28)
6310 verbose stack     at Pipe.<anonymous> (node:net:338:12)
6311 verbose pkgid [email protected]
6312 verbose cwd /dh/ws2/iris/web/client-ui
6313 verbose Linux 6.8.0-40-generic
6314 verbose node v20.13.1
6315 verbose npm  v10.5.2
6316 error code 127
6317 error path /dh/ws2/iris/web/client-ui/node_modules/lmdb
6318 error command failed
6319 error command sh -c node-gyp-build-optional-packages
6320 error sh: 1: node-gyp-build-optional-packages: not found

sorry if there's some additional debugging info that should be provided; I do general devops, and am helping our web team fix this build error ("it works on my machine, but dies in CI [because we enforce --no-bin-links in CI]").

JamesXNelson avatar Oct 22 '24 08:10 JamesXNelson

fwiw, adding --ignore-scripts has enabled us to move past this, but I really dislike arbitrarily disabling things I don't really understand in order to workaround a problem.

JamesXNelson avatar Oct 22 '24 16:10 JamesXNelson

In the case of node-gyp-build (or the node-gyp-build-optional-packages fork that lmdb employs) it is safe to use --ignore-scripts if a prebuilt binary is available for the platform that you're running on (assuming you have no other reason to compile it yourself). The script checks if a compatible prebuild exists, and if not, falls back to compiling the addon (lmdb).

vweevers avatar Oct 22 '24 17:10 vweevers

ok. I was trying to avoid --ignore-scripts in case something else needed it, but our build seems to be fine w/ this disabled.

I think perhaps some additional testing around --no-bin-links so that is doesn't try to sh node-gyp-build when it's not on the PATH may help others in the future.

JamesXNelson avatar Oct 25 '24 18:10 JamesXNelson

IMO use of --no-bin-links is at your own risk, because it's an essential feature for npm scripts. There is no alternative that has the same level of convenience.

vweevers avatar Oct 25 '24 21:10 vweevers