Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DeeDeeG opened this issue Mar 8, 2021 · 8 comments
Open

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

DeeDeeG opened this issue Mar 8, 2021 · 8 comments
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release

Comments

@DeeDeeG
Copy link

DeeDeeG commented Mar 8, 2021

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

@DeeDeeG DeeDeeG added Bug thing that needs fixing Needs Triage needs review for next steps Release 7.x work is associated with a specific npm 7 release labels Mar 8, 2021
@DeeDeeG
Copy link
Author

DeeDeeG commented Mar 10, 2021

I tested this by "poisoning" a copy of node-gyp so I'd be sure if it was used or not.

Simply put this at the beginning of the node-gyp/bin/node-gyp.js file:

throw new Error('hello from poisoned node-gyp')

I used to be able to specify what copy of node-gyp npm used with the node-gyp config var, but this stopped working in npm 7.


I didn't see any RFCs about this, so it's either an undocumented behavior change, or it's an oversight/bug.

I'd appreciate some clarity on whether it's meant to be deprecated or dropped functionality, in which case documenting that somewhere would be great, or if it's considered a bug, some pointers on how to get the bug fixed.

@DeeDeeG DeeDeeG changed the title [BUG] "node-gyp" config not respected in npm 7. (Sets a path to a custom copy of node-gyp to use.) (Set as: an env var "npm_config_node_gyp", or via "node-gyp" key in .npmrc, or with the "--node-gyp=some_path" flag on CLI) [BUG] "node-gyp" config var not respected in npm 7 Mar 12, 2021
@DeeDeeG DeeDeeG changed the title [BUG] "node-gyp" config var not respected in npm 7 [BUG] node-gyp config var not respected in npm 7 Mar 25, 2021
@DeeDeeG DeeDeeG changed the title [BUG] node-gyp config var not respected in npm 7 [BUG] config var "node-gyp" not respected in npm 7 Mar 25, 2021
@tavrez
Copy link

tavrez commented Apr 25, 2021

I also find this issue, but I think it's node_gyp not node-gyp, am I right?

@DeeDeeG
Copy link
Author

DeeDeeG commented Apr 25, 2021

@tavrez thanks for another person confirming this issue.

Both variable names (with underscore or dash) can be used interchangeably, at least in npm 6.

  • Env var npm_config_node_gyp or npm_config_node-gyp (this var name works in a case-insensitive way)
  • npm config var set in a .npmrc file, as npm config set node_gyp or npm config set node-gyp (also case-insensitive)
  • Command-line flag for npm:
    • npm rebuild --verbose --node_gyp=[path/to/node-gyp/bin/node-gyp.js] (flag --node-gyp must be all lowercase), or
    • npm rebuild --verbose --node-gyp=[path/to/node-gyp/bin/node-gyp.js] (flag --node_gyp also must be all lowercase)

@DeeDeeG
Copy link
Author

DeeDeeG commented Apr 29, 2021

I have a CI test that uses this npm config var to test whether spaces in paths can cause an issue.

I would have to disable or re-write the test if we upgrade our infrastructure to use npm 7 instead of npm 6. Any thoughts on whether this might be fixed, or labelled "won'tfix", would be appreciated so I can know whether to re-write/delete the test, or just wait for the fix.

Thanks.

@darcyclarke
Copy link
Contributor

This is a known issue; We'll try to resolve this when we upgrade to node-gyp@8.x in the very near future.

@DeeDeeG
Copy link
Author

DeeDeeG commented Jul 2, 2021

I think this is an unintended consequence of npm/run-script@e4c7cb3 ?

Might be the same underlying cause as what causes #3058.

@Hazmi35
Copy link

Hazmi35 commented Nov 11, 2021

This is a known issue; We'll try to resolve this when we upgrade to node-gyp@8.x in the very near future.

Sorry for the bump, but any progress on this issue and also #3058? I can't use Visual Studio 2022 with this, it is supported in node-gyp v8.4.0 but it is not bundled even with the latest release of npm.

The only workaround for that is install node-gyp in the project locally as dev dependencies, but I can't find the reason why npm_config_node_gyp isn't respected in npm v7.x anymore

Yes I know this is related to npm/run-script#23

@satoufuyuki
Copy link

Any progress?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

5 participants