nodejs / node-gyp

Node.js native addon build tool

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot update npm's node-gyp and thus gyp ERR! stack TypeError:

JakeWilsonSalesforce opened this issue · comments

  • Node Version: v20.11.0, 10.2.4
  • Platform: Darwin user1-ltmuwbz.internal.mycompany.com 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000 arm64
  • Compiler: Apple clang version 15.0.0 (clang-1500.0.40.1)
  • Module: (unpublished)

I am running into the all-too-common error:

gyp ERR! stack TypeError: Cannot assign to read only property 'cflags' of object '#<Object>'

After much research and troubleshooting and jumping through hoops it sounds like this is due to the latest Python 3.12 being incompatible with node-gyp 7.x.

I running the latest stable Node v20.11.0 and npm 10.2.4 on OSX 14.2.1. I am not using nvm.

I have followed the instructions here: https://github.com/nodejs/node-gyp/blob/main/docs/Updating-npm-bundled-node-gyp.md. Supposedly these instructions were to update the internally installed version of node-gyp that npm uses. I did this and no errors.

But when I run npm i in my project I get this:

npm ERR! code 1
npm ERR! path /Users/user1/repos/company-project/node_modules/node-sass
npm ERR! command failed
npm ERR! command sh -c node scripts/build.js
npm ERR! Building: /usr/local/bin/node /Users/user1/repos/company-project/node_modules/node-gyp/bin/node-gyp.js rebuild --verbose --libsass_ext= --libsass_cflags= --libsass_ldflags= --libsass_library=
npm ERR! gyp info it worked if it ends with ok
npm ERR! gyp verb cli [
npm ERR! gyp verb cli   '/usr/local/bin/node',
npm ERR! gyp verb cli   '/Users/user1/repos/company-project/node_modules/node-gyp/bin/node-gyp.js',
npm ERR! gyp verb cli   'rebuild',
npm ERR! gyp verb cli   '--verbose',
npm ERR! gyp verb cli   '--libsass_ext=',
npm ERR! gyp verb cli   '--libsass_cflags=',
npm ERR! gyp verb cli   '--libsass_ldflags=',
npm ERR! gyp verb cli   '--libsass_library='
npm ERR! gyp verb cli ]
npm ERR! gyp info using node-gyp@7.1.2
npm ERR! gyp info using node@20.11.0 | darwin | arm64
npm ERR! gyp verb command rebuild []
npm ERR! gyp verb command clean []
npm ERR! gyp verb clean removing "build" directory
npm ERR! gyp verb command configure []
npm ERR! gyp verb find Python Python is not set from command line or npm configuration
npm ERR! gyp verb find Python Python is not set from environment variable PYTHON
npm ERR! gyp verb find Python checking if "python3" can be used
npm ERR! gyp verb find Python - executing "python3" to get executable path
npm ERR! gyp verb find Python - executable path is "/Users/user1/.pyenv/versions/3.12.0/bin/python3"
npm ERR! gyp verb find Python - executing "/Users/user1/.pyenv/versions/3.12.0/bin/python3" to get version
npm ERR! gyp verb find Python - version is "3.12.0"
npm ERR! gyp info find Python using Python version 3.12.0 found at "/Users/user1/.pyenv/versions/3.12.0/bin/python3"
npm ERR! gyp verb get node dir no --target version specified, falling back to host node version: 20.11.0
npm ERR! gyp verb command install [ '20.11.0' ]
npm ERR! gyp verb install input version string "20.11.0"
npm ERR! gyp verb install installing version: 20.11.0
npm ERR! gyp verb install --ensure was passed, so won't reinstall if already installed
npm ERR! gyp verb install version is already installed, need to check "installVersion"
npm ERR! gyp verb got "installVersion" 9
npm ERR! gyp verb needs "installVersion" 9
npm ERR! gyp verb install version is good
npm ERR! gyp verb get node dir target node version installed: 20.11.0
npm ERR! gyp verb build dir attempting to create "build" dir: /Users/user1/repos/company-project/node_modules/node-sass/build
npm ERR! gyp verb build dir "build" dir needed to be created? /Users/user1/repos/company-project/node_modules/node-sass/build
npm ERR! gyp verb build/config.gypi creating config file
npm ERR! gyp ERR! UNCAUGHT EXCEPTION 
npm ERR! gyp ERR! stack TypeError: Cannot assign to read only property 'cflags' of object '#<Object>'
npm ERR! gyp ERR! stack     at createConfigFile (/Users/user1/repos/company-project/node_modules/node-gyp/lib/configure.js:117:21)
npm ERR! gyp ERR! stack     at /Users/user1/repos/company-project/node_modules/node-gyp/lib/configure.js:84:9
npm ERR! gyp ERR! stack     at FSReqCallback.oncomplete (node:fs:191:23)
npm ERR! gyp ERR! System Darwin 23.2.0
npm ERR! gyp ERR! command "/usr/local/bin/node" "/Users/user1/repos/company-project/node_modules/node-gyp/bin/node-gyp.js" "rebuild" "--verbose" "--libsass_ext=" "--libsass_cflags=" "--libsass_ldflags=" "--libsass_library="
npm ERR! gyp ERR! cwd /Users/user1/repos/company-project/node_modules/node-sass
npm ERR! gyp ERR! node -v v20.11.0
npm ERR! gyp ERR! node-gyp -v v7.1.2
npm ERR! gyp ERR! Node-gyp failed to build your package.
npm ERR! gyp ERR! Try to update npm and/or node-gyp and if it does not help file an issue with the package author.
npm ERR! Build failed with error code: 7

For some reason you can see that npm is still using node-gyp v7.1.2 instead of the latest version.

What is the problem here and how do I fix this?

I have even removed pyenv and python from my system and I still get the above error.

npm ERR! gyp info using node-gyp@7.1.2

Which is not https://github.com/nodejs/node-gyp/releases

I did this and no errors.

Please provide the commands typed and the full output.

Why did you close this ticket? I already pasted in all the error output above. The command I typed was simply npm install.

Also what do you mean by

Which is not https://github.com/nodejs/node-gyp/releases

NPM is choosing to use node-gyp 7.1.2. I did not install that locally or globally.