pnpm: pnpm causes `node-gyp rebuild` failures
pnpm version: 4.0.0, 4.0.2, 4.1.7
Last working version: 3.8.1
Code to reproduce the issue:
npm init -y
pnpm i better-sqlite3
Expected behavior:
better-sqlite3 is installed (as is the case with npm: npm i better-sqlite3
succeeds, which makes me think that the issue is with pnpm)
Actual behavior:
# pnpm i better-sqlite3
Packages: +11
+++++++++++
Resolving: total 11, reused 11, downloaded 0, done
node_modules/.pnpm/registry.npmjs.org/integer/2.1.0/node_modules/integer: Running install script, done in 2s
node_modules/.pnpm/registry.npmjs.org/better-sqlite3/5.4.3/node_modules/better-sqlite3: Running install script, failed in 393ms
.../5.4.3/node_modules/better-sqlite3 install$ node-gyp rebuild
│ gyp info it worked if it ends with ok
│ gyp info using node-gyp@6.0.0
│ gyp info using node@12.13.0 | linux | x64
│ gyp info find Python using Python version 3.6.8 found at "/usr/bin/python3"
│ gyp info spawn /usr/bin/python3
│ gyp info spawn args [
│ gyp info spawn args '/usr/lib/node_modules/pnpm/lib/node_modules/node-gyp/gyp/gyp_main.py',
│ gyp info spawn args 'binding.gyp',
│ gyp info spawn args '-f',
│ gyp info spawn args 'make',
│ gyp info spawn args '-I',
│ gyp info spawn args '/root/2/node_modules/.pnpm/registry.npmjs.org/better-sqlite3/5.4.3/node_modules/better-sqlite3/build/config.gypi',
│ gyp info spawn args '-I',
│ gyp info spawn args '/usr/lib/node_modules/pnpm/lib/node_modules/node-gyp/addon.gypi',
│ gyp info spawn args '-I',
│ gyp info spawn args '/root/.cache/node-gyp/12.13.0/include/node/common.gypi',
│ gyp info spawn args '-Dlibrary=shared_library',
│ gyp info spawn args '-Dvisibility=default',
│ gyp info spawn args '-Dnode_root_dir=/root/.cache/node-gyp/12.13.0',
│ gyp info spawn args '-Dnode_gyp_dir=/usr/lib/node_modules/pnpm/lib/node_modules/node-gyp',
│ gyp info spawn args '-Dnode_lib_file=/root/.cache/node-gyp/12.13.0/<(target_arch)/node.lib',
│ gyp info spawn args '-Dmodule_root_dir=/root/2/node_modules/.pnpm/registry.npmjs.org/better-sqlite3/5.4.3/node_modules/better-sqlite3',
│ gyp info spawn args '-Dnode_engine=v8',
│ gyp info spawn args '--depth=.',
│ gyp info spawn args '--no-parallel',
│ gyp info spawn args '--generator-output',
│ gyp info spawn args 'build',
│ gyp info spawn args '-Goutput_dir=.'
│ gyp info spawn args ]
│ Traceback (most recent call last):
│ File "/usr/lib/node_modules/pnpm/lib/node_modules/node-gyp/gyp/gyp_main.py", line 50, in <module>
│ sys.exit(gyp.script_main())
│ File "/usr/lib/node_modules/pnpm/lib/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 554, in script_main
│ return main(sys.argv[1:])
│ File "/usr/lib/node_modules/pnpm/lib/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 547, in main
│ return gyp_main(args)
│ File "/usr/lib/node_modules/pnpm/lib/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 532, in gyp_main
│ generator.GenerateOutput(flat_list, targets, data, params)
│ File "/usr/lib/node_modules/pnpm/lib/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 2215, in GenerateOutput
│ part_of_all=qualified_target in needed_targets)
│ File "/usr/lib/node_modules/pnpm/lib/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 794, in Write
│ extra_mac_bundle_resources, part_of_all)
│ File "/usr/lib/node_modules/pnpm/lib/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 978, in WriteActions
│ part_of_all=part_of_all, command=name)
│ File "/usr/lib/node_modules/pnpm/lib/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 1724, in WriteDoCmd
│ force = True)
│ File "/usr/lib/node_modules/pnpm/lib/node_modules/node-gyp/gyp/pylib/gyp/generator/make.py", line 1779, in WriteMakeRule
│ cmddigest = hashlib.sha1(command if command else self.target).hexdigest()
│ TypeError: Unicode-objects must be encoded before hashing
│ gyp ERR! configure error
│ gyp ERR! stack Error: `gyp` failed with exit code: 1
│ gyp ERR! stack at ChildProcess.onCpExit (/usr/lib/node_modules/pnpm/lib/node_modules/node-gyp/lib/configure.js:351:16)
│ gyp ERR! stack at ChildProcess.emit (events.js:210:5)
│ gyp ERR! stack at Process.ChildProcess._handle.onexit (internal/child_process.js:272:12)
│ gyp ERR! System Linux 4.15.0-33-generic
│ gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/pnpm/lib/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
│ gyp ERR! cwd /root/2/node_modules/.pnpm/registry.npmjs.org/better-sqlite3/5.4.3/node_modules/better-sqlite3
│ gyp ERR! node -v v12.13.0
│ gyp ERR! node-gyp -v v6.0.0
│ gyp ERR! not ok
└─ Failed in 393ms
ERROR Command failed with exit code 1.
(tried this on a fresh install of pnpm - with all of its stores removed)
Additional information:
node -v
prints: v12.13.0- Windows, OS X, or Linux?: Linux
About this issue
- Original URL
- State: open
- Created 5 years ago
- Reactions: 12
- Comments: 39 (14 by maintainers)
Commits related to this issue
- fix: the path to node-gyp should be added after the path to node_modules/.bin ref pnpm/pnpm#2135 — committed to pnpm/npm-lifecycle by zkochan 3 years ago
- fix: prefer node-gyp from dependencies over node-gyp that is bundled with pnpm CLI ref #2135 — committed to pnpm/pnpm by zkochan 3 years ago
- fix: prefer node-gyp from dependencies over node-gyp that is bundled with pnpm CLI ref #2135 — committed to pnpm/pnpm by zkochan 3 years ago
- Trying suggestion to fix broken windows build from https://github.com/pnpm/pnpm/issues/2135\#issuecomment-1260093143 — committed to vraravam/ferdium-app by vraravam 2 years ago
Still happening with
pnpm@8.6.10
&node@18.17.0
as of August 2023This problem still occurs in
7.5.1
This problem still occurs in pnpm
8.1.2
with node16.13.1
, but not in node14.15.3
.It is probably because pnpm switched to the latest version of node-gyp.
Maybe we can make it configurable
I was having a similar issue, on my project I have
node-linker=hoisted
in my.npmrc
file because otherwise I get an error trying to run the app. (probably related to webpack/webpack#5087).With the
hoisted
setting, the first time I dopnpm i
everything works. But if I try do do a subsequentpmp i
I get the following error:I don’t even understand why the error message says:
When the node modules are at:
Not sure what’s up with that. For me what worked was to do add
node-gyp-build
explicitly by doingpnpm i node-gyp-build
. After that I can dopnpm i
as many times as I want and all works as expected.@cclauss thanks for the npm tips! I’m looking to use pnpm as a package manager though, not npm.
For my case, setting the
child-concurrency
to1
in.npmrc
fixes the issue. It seems thatnode-gyp
builds are not thread-safe.https://github.com/atom-community/papm/blob/3c1b05e5abe2fba8c4e494e9568e99298c2b2ca4/.npmrc#L11
Has anybody solved the issue?
After upgrading
pnpm
version from6.32.11
to7.1.5
, this error showed up. I am usingnode 16.13.1
.This problem still occurs with
pnpm@8.9.0
,node@v18.18.1
as of October 2023.This might be related: https://github.com/pnpm/pnpm/pull/4020
pnpm was not setting
scripts-prepend-node-path
and it is set to true by default. So the scripts were executed using the Node.js environment that executed the pnpm CLI, which might differ from the globally installed Node.js environment. This setting should be off by default, not on.I would also love to see this implemented, prevents me from migrating to pnpm on an Electron project.
@zkochan any update on this? Need to switch back to npm because this prevents us from using pnpm.
The issue is also that pnpm is running
node-gyp rebuild
by itself, without us specifying it to run that. We already have apostinstall
script that handles building, not sure why pnpm tries to do it for us.