Skip to content

[BUG] config var "node-gyp" not respected in npm 7 #2839

@DeeDeeG

Description

@DeeDeeG

Current Behavior:

Unlike in npm v6, the node-gyp config var is not respected.

(This config option sets a custom path to a working node-gyp install's bin/node-gyp.js file. When set, npm will attempt to use this copy of node-gyp if executing node-gyp to build native C++ code.)

Expected Behavior:

node-gyp at the custom path is used. (At the path set in the node-gyp config var.)

Steps To Reproduce:

  1. If you don't have one already, obtain a copy of node-gyp (an extra copy not bundled with npm) and install its dependencies:
    i. git clone https://github.com/nodejs/node-gyp
    ii. cd node-gyp && npm install
  2. Specify a node-gyp config var somehow. See the following options to do so:
    a) Do npm config set node-gyp=/path/to/node-gyp/bin/node-gyp.js
    b1) Do export npm_config_node_gyp=/path/to/node-gyp/bin/node-gyp.js (Linux/macOS)
    b2) Do Set npm_config_node_gyp=C:/path/to/node-gyp/bin/node-gyp.js (Windows)
    c) Use this flag with npm commands: --node-gyp=/path/to/node-gyp/bin/node-gyp.js
  3. In any project that depends on a module with native code... run npm rebuild --verbose --foreground-scripts

Note that the path of node-gyp is printed next to a cli label in the verbose output.

For example (cli output, click to expand):
gyp verb cli [
gyp verb cli   '/Users/[user]/n-prefix/bin/node',
gyp verb cli   '/Users/[user]/n-prefix/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js',
gyp verb cli   'rebuild'
gyp verb cli ]
  • With npm 6, the node-gyp config var is respected, and the node-gyp at the custom path is used.
  • With npm 7, the node-gyp config var is not respected. Regardless of the config var, node-gyp bundled with the running npm is used, OR if there is a copy of node-gyp as a top-level dependency in the project's node_modules folder, that copy from the local node_modules/node-gyp is used.

Environment:

  • OS: macOS 10.15.7
  • Node: 12.4.0
  • npm: 7.6.1

Related issue?

I think I tracked down the problem to the @npmcli/run-script module. See this issue I created at that repository for my best guess as to why this is happening: npm/run-script#23

Metadata

Metadata

Assignees

Labels

Bugthing that needs fixingRelease 7.xwork is associated with a specific npm 7 release

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions