node-gyp
node-gyp copied to clipboard
Instructions to update bundled node-gyp do not work on Windows + npm >= 10
https://github.com/nodejs/node-gyp/blob/main/docs/Updating-npm-bundled-node-gyp.md#windows
These instructions fail for me using node v20.18.2 and npm 10.8.2.
I see similar reports on stackoverflow etc.
npm error code E404
npm error 404 Not Found - GET https://registry.npmjs.org/@npmcli%2fdocs - Not found
npm error 404
npm error 404 '@npmcli/docs@^1.0.0' is not in this registry.
npm error 404
npm error 404 Note that you can also install from a
npm error 404 tarball, folder, http url, or git url.
Would it be possible to create a GitHub Action that demonstrates this so we can all see how it fails?
Okay, here you go: https://github.com/tmm1/node-gyp-win32-test/actions/runs/15813828506/job/44569072771
It shows first where node-gyp is preinstalled:
/c/hostedtoolcache/windows/node/20.19.0/x64/node_modules/npm/node_modules/node-gyp/package.json: "version": "10.1.0",
Then it tries to install into that $NODE/node_modules/npm which fails with the message I posted above.
And finally you can see the npm ci invocation which calls node-gyp --version still prints 10.1 instead of 11.2
The solution is:
$nodePath = Split-Path -Parent (Get-Command node).Path
npm install --global --prefix $nodePath\\node_modules\\npm node-gyp@latest
Would you be willing to create a pull request to update those docs?
Also please consider creating a second job in that GitHub Actions file that demonstrates that the old still fails and the proposed solution passes?
I'm not able to invest in docs here. For posterity, I found that the documented solution for linux was quite slow and ended up using this instead:
# npm explore npm/node_modules/@npmcli/run-script -g -- npm_config_global=false npm install node-gyp@^11.2.0
npm install -g --prefix $(npm explore npm -g -- pwd)/../../../ [email protected]
rm -rf $(npm explore npm -g -- pwd)/node_modules/node-gyp
ln -nsf $(npm explore npm -g -- pwd)/../node-gyp $(npm explore npm -g -- pwd)/node_modules/