Node-gyp errors with Python while upgrading node version to 20.9.0

452 Views Asked by At

I am currently working on upgrading a service from node 14 to node 20.9.0, which I did, i updated the docker files and the nvmrc file..etc, but when i try to do npm install using node 20.9.0 i get these errors which are super frustrating, i cant find a way of fixing them, any ideas please?

npm ERR! path /Users/faljawhary/Desktop/forks/pkg-transformations/node_modules/node-expat
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp info using [email protected]
npm ERR! gyp info using [email protected] | darwin | arm64
npm ERR! gyp info find Python using Python version 3.9.6 found at "/Library/Developer/CommandLineTools/usr/bin/python3"
npm ERR! gyp http GET https://nodejs.org/download/release/v20.9.0/node-v20.9.0-headers.tar.gz
npm ERR! (node:22309) Warning: Setting the NODE_TLS_REJECT_UNAUTHORIZED environment variable to '0' makes TLS connections and HTTPS requests insecure by disabling certificate verification.
npm ERR! (Use `node --trace-warnings ...` to show where the warning was created)
npm ERR! gyp WARN install got an error, rolling back install
npm ERR! gyp ERR! configure error 
npm ERR! gyp ERR! stack FetchError: request to https://nodejs.org/download/release/v20.9.0/node-v20.9.0-headers.tar.gz failed, reason: 
npm ERR! gyp ERR! stack     at ClientRequest.<anonymous> (/Users/faljawhary/.nvm/versions/node/v20.9.0/lib/node_modules/npm/node_modules/minipass-fetch/lib/index.js:130:14)
npm ERR! gyp ERR! stack     at ClientRequest.emit (node:events:514:28)
npm ERR! gyp ERR! stack     at TLSSocket.socketErrorListener (node:_http_client:495:9)
npm ERR! gyp ERR! stack     at TLSSocket.emit (node:events:526:35)
npm ERR! gyp ERR! stack     at emitErrorNT (node:internal/streams/destroy:151:8)
npm ERR! gyp ERR! stack     at emitErrorCloseNT (node:internal/streams/destroy:116:3)
npm ERR! gyp ERR! stack     at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
npm ERR! gyp ERR! System Darwin 23.2.0
npm ERR! gyp ERR! command "/Users/faljawhary/.nvm/versions/node/v20.9.0/bin/node" "/Users/faljawhary/.nvm/versions/node/v20.9.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /Users/faljawhary/Desktop/forks/pkg-transformations/node_modules/node-expat
npm ERR! gyp ERR! node -v v20.9.0
npm ERR! gyp ERR! node-gyp -v v9.4.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in: /Users/faljawhary/.npm/_logs/2023-12-26T17_28_54_829Z-debug-0.log

I tried to install Python on my MAC, and i tried these commands:

pyenv install 2.7.18
pyenv global 2.7.18
export PATH="${HOME}/.pyenv/shims:${PATH}"
echo $PATH
npm config set python $(which python)
npm config list 

The error changed from "Python not found" to these new errors that i just mentioned above.

1

There are 1 best solutions below

0
AHousker On

If you can use yarn add instead you may have better luck.

I ran into this problem yesterday while trying to install an npm package shrink-ray-current via npm i shrink-ray-current --save. node-gyp was a dependency for that package which caused similar errors to what you have. I tried several things with npm, for example, but was unsuccessful with all of them. I don't know the specifics, but yarn handles dependency resolution differently than npm does.