npm / npm/cli

[BUG] failed optional dependency builds should not prevent global install of packages

Open
#7,355 8 comments 7 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

Is there an existing issue for this?
  • I have searched the existing issues
This issue exists in the latest npm version
  • I am using the latest npm
Current Behavior

With the inclusion of https://github.com/npm/cli/pull/7126 in v10.4 global installs of packages that have transient dependencies on packages like fsevents started failing.

Example Logs

npm ERR! code 1
npm ERR! path /Users/rigor789/.nvm/versions/node/v21.7.2/lib/node_modules/nativescript/node_modules/fsevents
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.1.0
npm ERR! gyp info using node@21.7.2 | darwin | arm64
npm ERR! gyp info find Python using Python version 3.9.6 found at "/Applications/Xcode-15.2.0.app/Contents/Developer/usr/bin/python3"
npm ERR! gyp info spawn /Applications/Xcode-15.2.0.app/Contents/Developer/usr/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args '/Users/rigor789/.nvm/versions/node/v21.7.2/lib/node_modules/nativescript/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/rigor789/.nvm/versions/node/v21.7.2/lib/node_modules/nativescript/node_modules/fsevents/build/config.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/Users/rigor789/.nvm/versions/node/v21.7.2/lib/node_modules/nativescript/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/Users/rigor789/Library/Caches/node-gyp/21.7.2/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/rigor789/Library/Caches/node-gyp/21.7.2',
npm ERR! gyp info spawn args '-Dnode_gyp_dir=/Users/rigor789/.nvm/versions/node/v21.7.2/lib/node_modules/nativescript/node_modules/node-gyp',
npm ERR! gyp info spawn args '-Dnode_lib_file=/Users/rigor789/Library/Caches/node-gyp/21.7.2/<(target_arch)/node.lib',
npm ERR! gyp info spawn args '-Dmodule_root_dir=/Users/rigor789/.nvm/versions/node/v21.7.2/lib/node_modules/nativescript/node_modules/fsevents',
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/rigor789/.nvm/versions/node/v21.7.2/lib/node_modules/nativescript/node_modules/fsevents) 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.<anonymous> (/Users/rigor789/.nvm/versions/node/v21.7.2/lib/node_modules/nativescript/node_modules/node-gyp/lib/configure.js:297:18)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:519:28)
npm ERR! gyp ERR! stack at ChildProcess._handle.onexit (node:internal/child_process:294:12)
npm ERR! gyp ERR! System Darwin 23.4.0
npm ERR! gyp ERR! command "/Users/rigor789/.nvm/versions/node/v21.7.2/bin/node" "/Users/rigor789/.nvm/versions/node/v21.7.2/lib/node_modules/nativescript/node_modules/.bin/node-gyp" "rebuild"
npm ERR! gyp ERR! cwd /Users/rigor789/.nvm/versions/node/v21.7.2/lib/node_modules/nativescript/node_modules/fsevents
npm ERR! gyp ERR! node -v v21.7.2
npm ERR! gyp ERR! node-gyp -v v10.1.0
npm ERR! gyp ERR! not ok

npm ERR! A complete log of this run can be found in: /Users/rigor789/.npm/_logs/2024-04-09T09_05_41_833Z-debug-0.log

Expected Behavior

Global installs should not fail. fsevents is an optional peerDependency, and installing it should not trigger a rebuild, nor fail on unsupported systems (like Linux/Windows).

Steps To Reproduce
  1. install npm 10.4 or newer
  2. run npm i -g nativescript
  3. the install will fail

To confirm the linked change breaks it:

  1. open node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js of your global packages
  2. edit line 1235 and comment out // fullMetadata: true,
  3. re-run: npm i -g nativescript
  4. the install works as expected.
Environment
  • npm: 10.4.0 (or newer)
  • Node.js: v21.7.2
  • OS Name: macOS Sonoma 14.4.1
  • System Model Name: MacBook Pro
  • npm config:
; "user" config from /Users/rigor789/.npmrc

//registry.npmjs.org/:_authToken = (protected)

; node bin location = /Users/rigor789/.nvm/versions/node/v21.7.2/bin/node
; node version = v21.7.2
; npm local prefix = /Users/rigor789/Code/
; npm version = 10.4.0
; cwd = /Users/rigor789/Code/
; HOME = /Users/rigor789
; Run `npm config ls -l` to show all defaults.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with node_modules/npm/node_modules/@npmcli/arborist/lib/arborist/build-ideal-tree.js around line 1235, especially the fullMetadata setting. Reproduce with npm i -g nativescript on npm 10.4 or newer and compare behavior after commenting out that setting. Done means the global install succeeds without rebuilding the optional fsevents dependency.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.