Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to rebuild with node-gyp@6.1.0 #2803

Closed
rilysh opened this issue Feb 23, 2023 · 7 comments
Closed

Failed to rebuild with node-gyp@6.1.0 #2803

rilysh opened this issue Feb 23, 2023 · 7 comments
Labels

Comments

@rilysh
Copy link

rilysh commented Feb 23, 2023

Trying to build a nodejs binding, whenever I run node-gyp rebuild it fails with Cannot assign to read only property 'cflags'. However, when I run node-gyp build I was successfully able to build it without any issues.

  • Node Version: v19.6.0
  • Platform: Linux tinyy 6.1.12_1 x86_64 GNU/Linux
  • Compiler: gcc version 12.2.0 (GCC)
Verbose output (from npm or node-gyp):
gyp info it worked if it ends with ok
gyp info using node-gyp@6.1.0
gyp info using node@19.6.0 | linux | x64
gyp info find Python using Python version 3.11.2 found at "/usr/bin/python3"
gyp ERR! UNCAUGHT EXCEPTION 
gyp ERR! stack TypeError: Cannot assign to read only property 'cflags' of object '#<Object>'
gyp ERR! stack     at createConfigFile (/home/rilysh/Desktop/simdjson_nodejs/node_modules/node-gyp/lib/configure.js:118:21)
gyp ERR! stack     at /home/rilysh/Desktop/simdjson_nodejs/node_modules/node-gyp/lib/configure.js:85:9
gyp ERR! stack     at /home/rilysh/Desktop/simdjson_nodejs/node_modules/mkdirp/index.js:30:20
gyp ERR! stack     at FSReqCallback.oncomplete (node:fs:181:23)
gyp ERR! System Linux 6.1.12_1
gyp ERR! command "/home/rilysh/.nvm/versions/node/v19.6.0/bin/node" "/home/rilysh/Desktop/simdjson_nodejs/node_modules/.bin/node-gyp" "rebuild"
gyp ERR! cwd /home/rilysh/Desktop/simdjson_nodejs
gyp ERR! node -v v19.6.0
gyp ERR! node-gyp -v v6.1.0
gyp ERR! This is a bug in `node-gyp`.
gyp ERR! Try to update node-gyp and file an Issue if it does not help:
gyp ERR!     <https://github.com/nodejs/node-gyp/issues>
npm ERR! code 7
npm ERR! path /home/rilysh/Desktop/simdjson_nodejs
npm ERR! command failed
npm ERR! command sh -c node-gyp rebuild

@cclauss cclauss added the Linux label Mar 2, 2023
@bio0z
Copy link

bio0z commented Apr 28, 2023

have the same

@cclauss cclauss added the ERR! node-gyp -v < v10.x.x npm install -g npm label Apr 28, 2023
@cclauss
Copy link
Contributor

cclauss commented Apr 28, 2023

@cclauss cclauss closed this as not planned Won't fix, can't repro, duplicate, stale Apr 28, 2023
@cclauss cclauss changed the title Failed to rebuild with node-gyp Failed to rebuild with node-gyp@6.1.0 Apr 28, 2023
@peterbe
Copy link

peterbe commented Sep 21, 2023

I'm stuck on this error too. Very cryptic.
It started to happen when I upgraded to latest remix and then had to upgrade from Node 16 to 20.

❯ npm --version
9.8.1
❯ node --version
v20.6.1

Error is:

npm ERR! code 7
npm ERR! path /Users/peterbe/dev/PETERBECOM/remix-peterbecom/node_modules/node-zopfli-es
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 node-gyp@7.1.0
npm ERR! gyp info using node@20.6.1 | darwin | x64
npm ERR! gyp info find Python using Python version 3.8.1 found at "/Users/peterbe/.pyenv/versions/3.8.1/Python.framework/Versions/3.8/bin/python3"
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/peterbe/dev/PETERBECOM/remix-peterbecom/node_modules/node-gyp/lib/configure.js:117:21)
npm ERR! gyp ERR! stack     at /Users/peterbe/dev/PETERBECOM/remix-peterbecom/node_modules/node-gyp/lib/configure.js:84:9
npm ERR! gyp ERR! stack     at FSReqCallback.oncomplete (node:fs:189:23)
npm ERR! gyp ERR! System Darwin 22.6.0
npm ERR! gyp ERR! command "/Users/peterbe/.nvm/versions/node/v20.6.1/bin/node" "/Users/peterbe/dev/PETERBECOM/remix-peterbecom/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /Users/peterbe/dev/PETERBECOM/remix-peterbecom/node_modules/node-zopfli-es
npm ERR! gyp ERR! node -v v20.6.1
npm ERR! gyp ERR! node-gyp -v v7.1.0
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.

I can see the gyp info using node-gyp@7.1.0 but I don't have node-gyp installed explicitly. I don't know what package pulls it in.

Tried to follow the instructions, but no luck:

❯ npm install --global node-gyp@latest
npm config set node_gyp $(npm prefix -g)/lib/node_modules/node-gyp/bin/node-gyp.js

changed 129 packages in 4s

17 packages are looking for funding
  run `npm fund` for details
npm ERR! `node_gyp` is not a valid npm option

npm ERR! A complete log of this run can be found in: /Users/peterbe/.npm/_logs/2023-09-21T00_01_50_296Z-debug-0.log

@cclauss
Copy link
Contributor

cclauss commented Sep 21, 2023

Newer versions of npm limit the number of config settings so node_gyp is not a valid npm option…

npm version
npm config list
npm config list -l
npm doctor

https://github.com/nodejs/node-gyp/blob/main/docs/Updating-npm-bundled-node-gyp.md

@peterbe
Copy link

peterbe commented Sep 21, 2023

I switched to Node 18 and now it worked.
Running out of energy at the moment to go back in there and try again.

When I had Node 20 in my terminal, and in my GitHub action actions/setup-node, it would crash with TypeError: Cannot assign to read only property 'cflags' of object '#<Object>'.
But once I switched to Node 18 in my terminal (using nvm) and in my GitHub Action, now npm ci just works again.

Now I have:

❯ node --version
v18.17.1

❯ npm --version
9.6.7

Sorry @cclauss that I'm not trying those commands there right now. But hopefully this note left here, for someone else, can unblock them if they too tried to fly to close to the sun (i.e. using Node 20).

@hafezdivandari
Copy link

After hours of headache, downgrading to Node 18 just worked, thanks @peterbe

@kapilshanaz
Copy link

kapilshanaz commented Jan 6, 2024

Adding dev dependencies
"node-gyp": "10.0.1", "nan": "2.18.0"
Also adding
"resolutions": { "nan": "2.18.0" }
to package.json worked for me for Node.JS 20 build failure

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants