watcher: gyp: binding.gyp not found (...) while trying to load binding.gyp
npm i @parcel/watcher fails with the error in the title when trying to install right after npm init. I’m sure this has something to do with my environment but I do not understand what is wrong.
node: 18.15.0 (installed via nvm) npm: 9.5.0 Python: 3.10.4 OS: macOS Ventura 13.4 Computer: Apple M1 Macbook Pro, 16-inch 2021
Full error:
npm ERR! code 1
npm ERR! path /Users/myuser/Documents/Dev/testgyp/node_modules/@parcel/watcher
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@9.3.1
npm ERR! gyp info using node@18.15.0 | darwin | arm64
npm ERR! gyp info find Python using Python version 3.10.4 found at "/Users/myuser/.pyenv/versions/3.10.4/bin/python3"
npm ERR! gyp info spawn /Users/myuser/.pyenv/versions/3.10.4/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args '/Users/myuser/.nvm/versions/node/v18.15.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py',
npm ERR! gyp info spawn args 'binding.gyp',
npm ERR! gyp info spawn args '-f',
npm ERR! gyp info spawn args 'make',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/Users/myuser/Documents/Dev/testgyp/node_modules/@parcel/watcher/build/config.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/Users/myuser/.nvm/versions/node/v18.15.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/Users/myuser/Library/Caches/node-gyp/18.15.0/include/node/common.gypi',
npm ERR! gyp info spawn args '-Dlibrary=shared_library',
npm ERR! gyp info spawn args '-Dvisibility=default',
npm ERR! gyp info spawn args '-Dnode_root_dir=/Users/myuser/Library/Caches/node-gyp/18.15.0',
npm ERR! gyp info spawn args '-Dnode_gyp_dir=/Users/myuser/.nvm/versions/node/v18.15.0/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args '-Dnode_lib_file=/Users/myuser/Library/Caches/node-gyp/18.15.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args '-Dmodule_root_dir=/Users/myuser/Documents/Dev/testgyp/node_modules/@parcel/watcher',
npm ERR! gyp info spawn args '-Dnode_engine=v8',
npm ERR! gyp info spawn args '--depth=.',
npm ERR! gyp info spawn args '--no-parallel',
npm ERR! gyp info spawn args '--generator-output',
npm ERR! gyp info spawn args 'build',
npm ERR! gyp info spawn args '-Goutput_dir=.'
npm ERR! gyp info spawn args ]
npm ERR! gyp: binding.gyp not found (cwd: /Users/myuser/Documents/Dev/testgyp/node_modules/@parcel/watcher) while trying to load binding.gyp
npm ERR! gyp ERR! configure error
npm ERR! gyp ERR! stack Error: `gyp` failed with exit code: 1
npm ERR! gyp ERR! stack at ChildProcess.onCpExit (/Users/myuser/.nvm/versions/node/v18.15.0/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:325:16)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:513:28)
npm ERR! gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:291:12)
npm ERR! gyp ERR! System Darwin 22.5.0
npm ERR! gyp ERR! command "/Users/myuser/.nvm/versions/node/v18.15.0/bin/node" "/Users/myuser/.nvm/versions/node/v18.15.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /Users/myuser/Documents/Dev/testgyp/node_modules/@parcel/watcher
npm ERR! gyp ERR! node -v v18.15.0
npm ERR! gyp ERR! node-gyp -v v9.3.1
npm ERR! gyp ERR! not ok
About this issue
- Original URL
- State: closed
- Created 10 months ago
- Reactions: 22
- Comments: 33 (3 by maintainers)
Commits related to this issue
- Update dependencies Override @parcel/watcher to 2.1.0 to work around https://github.com/parcel-bundler/watcher/issues/156 — committed to CallumWatkins/website by CallumWatkins 5 months ago
- chore(deps): Update JS depedencies.. include new directive to work around https://github.com/parcel-bundler/watcher/issues/156 — committed to johnbcodes/rust-quote-editor by johnbcodes 5 months ago
- Update phaser to 3.70 and "fix binding.gyp not found" issue https://github.com/parcel-bundler/watcher/issues/156 — committed to xbelanch/15 by xbelanch 5 months ago
- Publish watcher from sub-directory so binding.gyp is excluded #156 — committed to parcel-bundler/watcher by devongovett 4 months ago
Solution temp
package.json
I tried some more combinations of Node and npm:
Same here. My workaround:
Confirming the downgrade to npm v10.3.0 fixed the issue for me while using Node v20.11.0
Was on npm v10.4.0 and trying to set up Analog.js using
npm install @analogjs/platform --save-devand ran into this error:After downgrading, the install completed successfully.
As found out by vincesp, downgrading npm to v10.3.0 on Node 18.17.1 did help! I ran
npm install -g npm@10.3.0for the downgrade just fyi.Thanks!
I have the same exact error when installing Nuxt.
In my case @parcel/watcher is a direct dependency of another package. Solved by fixing version on that dependency:
"overrides": {"package-that-uses-parcel": {"@parcel/watcher": "2.1.0"}}Great info @lovell! Thanks so much for sharing. It’s interesting because this seems to have been happening even before npm 10.4 Perhaps that’s actually a different issue (with lockfiles?) though.
I updated our publishing workflow to copy the files needed into a separate directory and run npm publish from there. That way binding.gyp doesn’t get added by npm (even though it already wasn’t included in package.json
files).In a related change, I also added better error handling to the package so that if an error occurs while requiring the native module, we only continue trying fallback locations if the error was a module not found error. Other errors (e.g. incompatibilities with OS versions) are re-thrown so they are reported to users.
These changes are published in v2.4.1. I tested locally with npm 10.4.0 and was able to install the package successfully. Please let me know if you continue to run into issues.
First time trying Nuxt today, and I get this 😦
Can confirm that this causes fresh nuxt installations to fail when using
npx nuxi init. Quite annoying for people that are new to the framework since they won’t know they have to override the package.json to fix itI have the same exact error when installing Nuxt.
+1 Updated package.lock in nuxt 3 and thought it’s the infamous npm cache permissions bug. But even after chowning and reinstalling node, the error stayed. Turns out it was due to this package.
Tested overrides with all sorts of in-between versions. The first version to work is 2.1.0
Env: Node 21.6 OS macOS Sonoma Arch arm64 (M1 Pro)
@devongovett PR https://github.com/parcel-bundler/watcher/pull/144 removed the
installscript frompackage.jsonas part of v2.2.0 however the npm registry still reports aninstallscript:I think this erroneous
installscript is being injected atnpm publishtime because npm sees abinding.gypfile (thanks to the logic in @npmcli/node-gyp), however this file isn’t published.A few possible solutions, from hardest to easiest:
@npmcli/node-gypso it checks to see ifbinding.gypwill actually be published (e.g. look infilesor.npmignore).srcand related build files, includingbinding.gyp, out of the root directory of this repo so it no longer looks like a native module (I did this for sharp, it works a treat, removes a whole class of error in most Electron tooling as well).binding.gypfile from the filesystem just before runningnpm publish.npm v10.4.0 introduced https://github.com/npm/run-script/pull/192 which completely changes the way that
package.jsonfiles are parsed atnpm installtime and is likely to have exposed this issue.Can reproduce this with ‘npm install’ in a SolidJS project.
$ node –version v20.11.0 $ node-gyp –version v10.0.1 $ npm –version 10.4.0 $ uname -a Linux 6.7.3-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 01 Feb 2024 10:30:35 +0000 x86_64 GNU/Linux
[host@myhost site]$ npm install npm ERR! code 1 npm ERR! path /home/host/site/node_modules/@parcel/watcher 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@10.0.1 npm ERR! gyp info using node@20.11.0 | linux | x64 npm ERR! gyp info find Python using Python version 3.11.6 found at “/sbin/python3” npm ERR! gyp info spawn /sbin/python3 npm ERR! gyp info spawn args [ npm ERR! gyp info spawn args ‘/home/host/.nvm/versions/node/v20.11.0/lib/node_modules/npm/node_modules/node-gyp/gyp/gyp_main.py’, npm ERR! gyp info spawn args ‘binding.gyp’, npm ERR! gyp info spawn args ‘-f’, npm ERR! gyp info spawn args ‘make’, npm ERR! gyp info spawn args ‘-I’, npm ERR! gyp info spawn args ‘/home/host/site/node_modules/@parcel/watcher/build/config.gypi’, npm ERR! gyp info spawn args ‘-I’, npm ERR! gyp info spawn args ‘/home/host/.nvm/versions/node/v20.11.0/lib/node_modules/npm/node_modules/node-gyp/addon.gypi’, npm ERR! gyp info spawn args ‘-I’, npm ERR! gyp info spawn args ‘/home/host/.cache/node-gyp/20.11.0/include/node/common.gypi’, npm ERR! gyp info spawn args ‘-Dlibrary=shared_library’, npm ERR! gyp info spawn args ‘-Dvisibility=default’, npm ERR! gyp info spawn args ‘-Dnode_root_dir=/home/host/.cache/node-gyp/20.11.0’, npm ERR! gyp info spawn args ‘-Dnode_gyp_dir=/home/host/.nvm/versions/node/v20.11.0/lib/node_modules/npm/node_modules/node-gyp’, npm ERR! gyp info spawn args ‘-Dnode_lib_file=/home/host/.cache/node-gyp/20.11.0/<(target_arch)/node.lib’, npm ERR! gyp info spawn args ‘-Dmodule_root_dir=/home/host/site/node_modules/@parcel/watcher’, npm ERR! gyp info spawn args ‘-Dnode_engine=v8’, npm ERR! gyp info spawn args ‘–depth=.’, npm ERR! gyp info spawn args ‘–no-parallel’, npm ERR! gyp info spawn args ‘–generator-output’, npm ERR! gyp info spawn args ‘build’, npm ERR! gyp info spawn args ‘-Goutput_dir=.’ npm ERR! gyp info spawn args ] npm ERR! gyp: binding.gyp not found (cwd: /home/host/site/node_modules/@parcel/watcher) while trying to load binding.gyp npm ERR! gyp ERR! configure error npm ERR! gyp ERR! stack Error:
gypfailed with exit code: 1 npm ERR! gyp ERR! stack at ChildProcess.<anonymous> (/home/host/.nvm/versions/node/v20.11.0/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:271:18) npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:518:28) npm ERR! gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:294:12) npm ERR! gyp ERR! System Linux 6.7.3-arch1-1 npm ERR! gyp ERR! command “/home/host/.nvm/versions/node/v20.11.0/bin/node” “/home/host/.nvm/versions/node/v20.11.0/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js” “rebuild” npm ERR! gyp ERR! cwd /home/host/site/node_modules/@parcel/watcher npm ERR! gyp ERR! node -v v20.11.0 npm ERR! gyp ERR! node-gyp -v v10.0.1 npm ERR! gyp ERR! not oknpm ERR! A complete log of this run can be found in: /home/host/.npm/_logs/2024-02-05T14_27_16_860Z-debug-0.log
Having the same issue since at least Aug 16: node: v18.17.1 npm: v9.6.7 Tried downgrading to node 16.15 (npm 8.11), same error. Also tried forcing @parcel/watcher version to 2.1 and 2.3.