npm / cli

the package manager for JavaScript
https://docs.npmjs.com/cli/
Other
8.46k stars 3.15k forks source link

[BUG] `npm update` duplicates `node-gyp` arguments and fails to build dependency #7879

Open ZedThree opened 1 week ago

ZedThree commented 1 week ago

Is there an existing issue for this?

This issue exists in the latest npm version

Current Behavior

Running npm update fails when calling node-gyp build because some of the arguments are duplicated. The package is: "tree-sitter-fortran": "git://github.com/stadelmanma/tree-sitter-fortran.git", and I can see in the error message:

...
npm error gyp info spawn /usr/bin/python3
npm error gyp info spawn args [
npm error gyp info spawn args '/usr/lib64/node_modules/npm22/node_modules/node-gyp/gyp/gyp_main.py',
npm error gyp info spawn args 'binding.gyp',
npm error gyp info spawn args '/usr/lib64/node_modules/npm22/node_modules/node-gyp/gyp/gyp_main.py',
npm error gyp info spawn args 'binding.gyp',
...

and, later, the error:

npm error   File "/usr/lib64/node_modules/npm22/node_modules/node-gyp/gyp/gyp_main.py", line 7
npm error     import os
npm error     ^^^^^^
npm error SyntaxError: invalid syntax

Notice that in the first snippet we essentially end up with gyp_main.py binding.gyp gyp_main.py binding.gyp .... This tries to use gyp_main.py as a build file, which I guess is causing the SyntaxError in the second snippet.

Full output: ``` $ npm update npm error code 7 npm error git dep preparation failed npm error command /usr/bin/node22 /usr/lib64/node_modules/npm22/bin/npm-cli.js install --force --cache=/home/peter/.npm --prefer-offline=false --prefer-online=false --offline=false --no-progress --no-save --no-audit --include=dev --include=peer --include=optional --no-package-lock-only --no-dry-run npm error > tree-sitter-fortran@0.2.0 install npm error > node-gyp-build npm error npm warn using --force Recommended protections disabled. npm error gyp info it worked if it ends with ok npm error gyp info using node-gyp@10.1.0 npm error gyp info using node@22.3.0 | linux | x64 npm error gyp info find Python using Python version 3.11.10 found at "/usr/bin/python3" npm error gyp info spawn /usr/bin/python3 npm error gyp info spawn args [ npm error gyp info spawn args '/usr/lib64/node_modules/npm22/node_modules/node-gyp/gyp/gyp_main.py', npm error gyp info spawn args 'binding.gyp', npm error gyp info spawn args '-f', npm error gyp info spawn args 'make', npm error gyp info spawn args '-I', npm error gyp info spawn args '/home/peter/.npm/_cacache/tmp/git-cloneXXXXXX7MIWmy/build/config.gypi', npm error gyp info spawn args '-I', npm error gyp info spawn args '/home/peter/.npm/_cacache/tmp/git-cloneXXXXXX7MIWmy/build/config.gypi', npm error gyp info spawn args '-I', npm error gyp info spawn args '/home/peter/.npm/_cacache/tmp/git-cloneXXXXXX7MIWmy/build/config.gypi', npm error gyp info spawn args '-I', npm error gyp info spawn args '/home/peter/.npm/_cacache/tmp/git-cloneXXXXXX7MIWmy/build/config.gypi', npm error gyp info spawn args '-I', npm error gyp info spawn args '/usr/lib64/node_modules/npm22/node_modules/node-gyp/addon-rpm.gypi', npm error gyp info spawn args '-I', npm error gyp info spawn args '/usr/include/node22/common.gypi', npm error gyp info spawn args '-Dlibrary=shared_library', npm error gyp info spawn args '-Dvisibility=default', npm error gyp info spawn args '-Dnode_root_dir=/usr/include/node22', npm error gyp info spawn args '-Dnode_gyp_dir=/usr/lib64/node_modules/npm22/node_modules/node-gyp', npm error gyp info spawn args '-Dnode_lib_file=/usr/include/node22/<(target_arch)/node.lib', npm error gyp info spawn args '-Dmodule_root_dir=/home/peter/.npm/_cacache/tmp/git-cloneXXXXXX7MIWmy', npm error gyp info spawn args '-Dnode_engine=v8', npm error gyp info spawn args '--depth=.', npm error gyp info spawn args '--no-parallel', npm error gyp info spawn args '--generator-output', npm error gyp info spawn args 'build', npm error gyp info spawn args '-Goutput_dir=.' npm error gyp info spawn args ] npm error gyp info spawn /usr/bin/python3 npm error gyp info spawn args [ npm error gyp info spawn args '/usr/lib64/node_modules/npm22/node_modules/node-gyp/gyp/gyp_main.py', npm error gyp info spawn args 'binding.gyp', npm error gyp info spawn args '/usr/lib64/node_modules/npm22/node_modules/node-gyp/gyp/gyp_main.py', npm error gyp info spawn args 'binding.gyp', npm error gyp info spawn args '-f', npm error gyp info spawn args 'make', npm error gyp info spawn args '-I', npm error gyp info spawn args '/home/peter/.npm/_cacache/tmp/git-cloneXXXXXX7MIWmy/build/config.gypi', npm error gyp info spawn args '-I', npm error gyp info spawn args '/home/peter/.npm/_cacache/tmp/git-cloneXXXXXX7MIWmy/build/config.gypi', npm error gyp info spawn args '-I', npm error gyp info spawn args '/home/peter/.npm/_cacache/tmp/git-cloneXXXXXX7MIWmy/build/config.gypi', npm error gyp info spawn args '-I', npm error gyp info spawn args '/home/peter/.npm/_cacache/tmp/git-cloneXXXXXX7MIWmy/build/config.gypi', npm error gyp info spawn args '-I', npm error gyp info spawn args '/usr/lib64/node_modules/npm22/node_modules/node-gyp/addon-rpm.gypi', npm error gyp info spawn args '-I', npm error gyp info spawn args '/usr/include/node22/common.gypi', npm error gyp info spawn args '-Dlibrary=shared_library', npm error gyp info spawn args '-Dvisibility=default', npm error gyp info spawn args '-Dnode_root_dir=/usr/include/node22', npm error gyp info spawn args '-Dnode_gyp_dir=/usr/lib64/node_modules/npm22/node_modules/node-gyp', npm error gyp info spawn args '-Dnode_lib_file=/usr/include/node22/<(target_arch)/node.lib', npm error gyp info spawn args '-Dmodule_root_dir=/home/peter/.npm/_cacache/tmp/git-cloneXXXXXX7MIWmy', npm error gyp info spawn args '-Dnode_engine=v8', npm error gyp info spawn args '--depth=.', npm error gyp info spawn args '--no-parallel', npm error gyp info spawn args '--generator-output', npm error gyp info spawn args 'build', npm error gyp info spawn args '-Goutput_dir=.', npm error gyp info spawn args '-I', npm error gyp info spawn args '/usr/lib64/node_modules/npm22/node_modules/node-gyp/addon-rpm.gypi', npm error gyp info spawn args '-I', npm error gyp info spawn args '/usr/include/node22/common.gypi', npm error gyp info spawn args '-Dlibrary=shared_library', npm error gyp info spawn args '-Dvisibility=default', npm error gyp info spawn args '-Dnode_root_dir=/usr/include/node22', npm error gyp info spawn args '-Dnode_gyp_dir=/usr/lib64/node_modules/npm22/node_modules/node-gyp', npm error gyp info spawn args '-Dnode_lib_file=/usr/include/node22/<(target_arch)/node.lib', npm error gyp info spawn args '-Dmodule_root_dir=/home/peter/.npm/_cacache/tmp/git-cloneXXXXXX7MIWmy', npm error gyp info spawn args '-Dnode_engine=v8', npm error gyp info spawn args '--depth=.', npm error gyp info spawn args '--no-parallel', npm error gyp info spawn args '--generator-output', npm error gyp info spawn args 'build', npm error gyp info spawn args '-Goutput_dir=.' npm error gyp info spawn args ] npm error Traceback (most recent call last): npm error File "/usr/lib64/node_modules/npm22/node_modules/node-gyp/gyp/gyp_main.py", line 45, in npm error sys.exit(gyp.script_main()) npm error ^^^^^^^^^^^^^^^^^ npm error File "/usr/lib64/node_modules/npm22/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 688, in script_main npm error return main(sys.argv[1:]) npm error ^^^^^^^^^^^^^^^^^^ npm error File "/usr/lib64/node_modules/npm22/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 680, in main npm error return gyp_main(args) npm error ^^^^^^^^^^^^^^ npm error File "/usr/lib64/node_modules/npm22/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 647, in gyp_main npm error [generator, flat_list, targets, data] = Load( npm error ^^^^^ npm error File "/usr/lib64/node_modules/npm22/node_modules/node-gyp/gyp/pylib/gyp/__init__.py", line 157, in Load npm error result = gyp.input.Load( npm error ^^^^^^^^^^^^^^^ npm error File "/usr/lib64/node_modules/npm22/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 2985, in Load npm error LoadTargetBuildFile( npm error File "/usr/lib64/node_modules/npm22/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 400, in LoadTargetBuildFile npm error build_file_data = LoadOneBuildFile( npm error ^^^^^^^^^^^^^^^^^ npm error File "/usr/lib64/node_modules/npm22/node_modules/node-gyp/gyp/pylib/gyp/input.py", line 237, in LoadOneBuildFile npm error build_file_data = eval(build_file_contents, {"__builtins__": {}}, None) npm error ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ npm error File "/usr/lib64/node_modules/npm22/node_modules/node-gyp/gyp/gyp_main.py", line 7 npm error import os npm error ^^^^^^ npm error SyntaxError: invalid syntax npm error gyp ERR! UNCAUGHT EXCEPTION npm error gyp ERR! stack Error: `gyp` failed with exit code: 1 npm error gyp ERR! stack at ChildProcess. (/usr/lib64/node_modules/npm22/node_modules/node-gyp/lib/configure.js:307:18) npm error gyp ERR! stack at ChildProcess.emit (node:events:520:28) npm error gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:294:12) npm error gyp ERR! System Linux 6.11.0-1-default npm error gyp ERR! command "/usr/bin/node22" "/usr/lib64/node_modules/npm22/node_modules/node-gyp/bin/node-gyp.js" "rebuild" npm error gyp ERR! cwd /home/peter/.npm/_cacache/tmp/git-cloneXXXXXX7MIWmy npm error gyp ERR! node -v v22.3.0 npm error gyp ERR! node-gyp -v v10.1.0 npm error gyp ERR! Node-gyp failed to build your package. npm error gyp ERR! Try to update npm and/or node-gyp and if it does not help file an issue with the package author. npm error npm error code 7 npm error npm error path /home/peter/.npm/_cacache/tmp/git-cloneXXXXXX7MIWmy npm error npm error command failed npm error npm error command sh -c node-gyp-build npm error npm error A complete log of this run can be found in: /home/peter/.npm/_logs/2024-10-25T13_24_18_134Z-debug-0.log npm error A complete log of this run can be found in: /home/peter/.npm/_logs/2024-10-25T13_24_16_089Z-debug-0.log ```

If I run node-gyp build manually in a local clone of tree-sitter-fortran, it works fine.

Expected Behavior

npm update completes without error and builds the latest version of the dependency

Steps To Reproduce

Run:

$ npm init
# default answers
$ npm install --save-dev git://github.com/stadelmanma/tree-sitter-fortran.git
# fails

or alternatively:

$ git clone https://github.com/stadelmanma/tree-sitter-fortran.git
$ cd tree-sitter-fortran
$ npm install
# fails

Note that in this case, running node-gyp build directly does work

Environment

legacy-peer-deps = true prefix = "/home/peter/.local"

; node bin location = /usr/bin/node22 ; node version = v22.3.0 ; npm local prefix = /tmp/test_npm ; npm version = 10.8.1 ; cwd = /tmp/test_npm ; HOME = /home/peter ; Run npm config ls -l to show all defaults.

milaninfy commented 1 day ago

it works for me apart from OS ( i am using mac ) all the parameters and config is same

Now using node v22.3.0 (npm v10.8.1)
~/workarea/rep $ npm install --save-dev git://github.com/stadelmanma/tree-sitter-fortran.git

added 5 packages, and audited 6 packages in 55s

found 0 vulnerabilities
~/workarea/rep $ 
ZedThree commented 10 hours ago

So presumably something in my environment causing this? Any ideas on how I could further debug this?