npm / npm/cli

[BUG] NPM 8 cannot global install some kind of modules with bundledDependencies on Linux

Open
#5,604 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Needs Triage Release 8.x
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

I have made a very simple module which just depends on the chokidar module and has bundledDependencies on an empty node module that just have a package.json file.

After I created the package of the simple module by running the command: npm pack, I tried to globally install the package on my Linux VM and get the following errors:

user: projects $ npm install -g testchokidar-1.0.0.tgz
npm WARN config global --global, --local are deprecated. Use --location=global instead.
npm notice
npm notice New minor version of npm available! 8.11.0 -> 8.19.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.19.2
npm notice Run npm install -g npm@8.19.2 to update!
npm notice
npm ERR! code 1
npm ERR! path /home/user/.node_modules_global/lib/node_modules/testchokidar/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@9.0.0
npm ERR! gyp info using node@16.16.0 | linux | x64
npm ERR! gyp info find Python using Python version 3.9.2 found at "/usr/bin/python3"
npm ERR! gyp http GET https://nodejs.org/download/release/v16.16.0/node-v16.16.0-headers.tar.gz
npm ERR! gyp http 200 https://nodejs.org/download/release/v16.16.0/node-v16.16.0-headers.tar.gz
npm ERR! gyp http GET https://nodejs.org/download/release/v16.16.0/SHASUMS256.txt
npm ERR! gyp http 200 https://nodejs.org/download/release/v16.16.0/SHASUMS256.txt
npm ERR! gyp info spawn /usr/bin/python3
npm ERR! gyp info spawn args [
npm ERR! gyp info spawn args '/opt/nodejs/node-v16.16.0-linux-x64/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/user/.node_modules_global/lib/node_modules/testchokidar/node_modules/fsevents/build/config.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/opt/nodejs/node-v16.16.0-linux-x64/lib/node_modules/npm/node_modules/node-gyp/addon.gypi',
npm ERR! gyp info spawn args '-I',
npm ERR! gyp info spawn args '/home/user/.cache/node-gyp/16.16.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/user/.cache/node-gyp/16.16.0',
npm ERR! gyp info spawn args '-Dnode_gyp_dir=/opt/nodejs/node-v16.16.0-linux-x64/lib/node_modules/npm/node_modules/node-gyp',
npm ERR! gyp info spawn args '-Dnode_lib_file=/home/user/.cache/node-gyp/16.16.0/<(target_arch)/node.lib',
npm ERR! gyp info spawn args '-Dmodule_root_dir=/home/user/.node_modules_global/lib/node_modules/testchokidar/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: /home/user/.node_modules_global/lib/node_modules/testchokidar/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.onCpExit (/opt/nodejs/node-v16.16.0-linux-x64/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js:261:16)
npm ERR! gyp ERR! stack at ChildProcess.emit (node:events:527:28)
npm ERR! gyp ERR! stack at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
npm ERR! gyp ERR! System Linux 5.10.114-garden-cloud-amd64
npm ERR! gyp ERR! command "/opt/nodejs/node-v16.16.0-linux-x64/bin/node" "/opt/nodejs/node-v16.16.0-linux-x64/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
npm ERR! gyp ERR! cwd /home/user/.node_modules_global/lib/node_modules/testchokidar/node_modules/fsevents
npm ERR! gyp ERR! node -v v16.16.0
npm ERR! gyp ERR! node-gyp -v v9.0.0
npm ERR! gyp ERR! not ok

fsevents is only for MacOS, so I do not know why NPM will try to compile it on Linux.

Expected Behavior

I expected the simple module could be globally installed on Linux and NPM should ignore the fsevents module on Linux.

Steps To Reproduce
  1. Initialize a simple project by using the command: npm init
  2. Add a dependency on chokidar by running the command: npm install chokidar
  3. Add the packages folder under the root folder of the simple project
  4. In the packages folder, create a empty project by just using the command: npm init
  5. In the package.json file of the simple project, add the bundledDependencies on the empty project. For example,

{
"name": "testchokidar",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"bin": {
"test-chokidar": "index.js"
},
"author": "",
"license": "ISC",
"dependencies": {
"chokidar": "^3.5.3"
},
"bundledDependencies": [
"packages/simplest"
]
}

  1. Pack the simple project by using the command: npm pack.
  2. Globally install the above packed package on Linux by using the command: npm install -g testchokidar-1.0.0.tgz
  3. Then you can find the global installation failed with the errors that are pasted in Current Behavior
Environment
  • npm: 8.11.0
  • Node.js: v16.16.0
  • OS Name: Linux
  • System Model Name:
  • npm config:
; ; "user" config from /home/user/.npmrc

prefix = "/home/user/.node_modules_global" 
registry = "http://nginx-redirector.repo-cache.svc.cluster.local/repository/appstudio-npm-group/" 

; "env" config from environment

userconfig = "/home/user/.npmrc" 

; node bin location = /opt/nodejs/node-v16.16.0-linux-x64/bin/node
; node version = v16.16.0
; npm local prefix = /home/user
; npm version = 8.11.0
; cwd = /home/user/projects
; HOME = /home/user
; 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

Reproduce the issue with npm init, npm install chokidar, npm pack, and npm install -g on Linux, focusing on the bundledDependencies package and fsevents. Trace npm CLI handling of bundled and platform-specific dependencies; done means the packed package installs globally on Linux without attempting to build fsevents.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.