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] npx node-gyp@version runs the copy of node-gyp bundled with npm instead #3058

Closed
Tracked by #403
DeeDeeG opened this issue Apr 10, 2021 · 6 comments
Closed
Tracked by #403
Assignees
Labels
Bug thing that needs fixing cmd:exec related to `npx` Priority 2 secondary priority issue Release 7.x work is associated with a specific npm 7 release

Comments

@DeeDeeG
Copy link

DeeDeeG commented Apr 10, 2021

Current Behavior:

  • npx node-gyp@8 runs the older node-gyp 7.1.2 that is bundled with npm.
    • /home/[me]/n-prefix/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js

Same result if doing plain npx node-gyp. The latest version is v8.0.0, but v7.1.2 is used instead. Happens even if node-gyp v8 is installed globally, and no node-gyp is installed in the location npx is run from.

Expected Behavior:

A separate npx-specific copy of node-gyp v8 should run. Or when node-gyp v8 is installed globally, that could be used.

Steps To Reproduce:

npx node-gyp or npx node-gyp@8 or npx node-gyp@8.0.0, etc.

Environment:

  • OS: Ubuntu 20.04, macOS 10.15.7 Catalina, Windows 10
  • Node: v14.16.1, v16.0.0-nightly2021041040ace47396
  • npm: 7.9.0
@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 Apr 10, 2021
@nlf
Copy link
Contributor

nlf commented Apr 13, 2021

i can confirm this, and i see the reason it's happening, but i need to do a bit of research to see why the code is the way it is before we can consider changing it. i'll do some digging and follow up here when i have an answer

@nlf nlf added Priority 2 secondary priority issue and removed Needs Triage needs review for next steps labels Apr 13, 2021
@nlf nlf self-assigned this Apr 13, 2021
@DeeDeeG
Copy link
Author

DeeDeeG commented Apr 13, 2021

I filed another issue that seems related or at least tangentially related: #2839. I suppose they might be solved at the same time, depending on what the exact details turn out to be.

@DeeDeeG
Copy link
Author

DeeDeeG commented Jul 2, 2021

I think this started with npm/run-script@e4c7cb3.

As of that commit, @npmcli/run-script adds its bundled node-gyp executable/shim to the PATH. That shim is added relatively early in the PATH (earlier than the dir with npx's downloaded modules). And then @npmcli/run-script runs sh -c node-gyp [args].

So I think the wrong node-gyp is run via what's first in the PATH. (It is always @npmcli/run-script's shim.)

When debugging the execution with node --inspect-brk /home/[me]/npm/cli/bin/npx-cli.js I end up with a PATH var like this:

/home/[me]/[project I'm working in]/node_modules/.bin:/home/[me]/node_modules/.bin:/home/node_modules/.bin:/node_modules/.bin:/home/[me]/npm/cli/node_modules/@npmcli/run-script/lib/node-gyp-bin:/home/[me]/.npm/_npx/[lots o' digits]/node_modules/.bin:[ . . . rest of PATH is my usual PATH content and is not npm-related . . . ]

Note these two:

  • /home/[me]/npm/cli/node_modules/@npmcli/run-script/lib/node-gyp-bin
  • home/[me]/.npm/_npx/[lots o' digits]/node_modules/.bin

First we have @npmcli/run-script's dir with a node-gyp shim in it, just before home/[me]/.npm/_npx/[lots o' digits]/node_modules/.bin where the npx modules are stored, including the npx copy of node-gyp.

So I do think this has a similar cause to #2839.

@tavrez
Copy link

tavrez commented Oct 14, 2021

I think this is fixed in v8 of npm
Edit: nope, it's not

@DeeDeeG
Copy link
Author

DeeDeeG commented Nov 7, 2021

Yeah, it's probably not fixed, just that node-gyp 8 is now the bundled version of node-gyp as of npm 8.

Edit: Yep, the latest npm, npm 8.1.3, is still affected.

@DeeDeeG DeeDeeG changed the title [BUG] npx node-gyp@8 runs the copy of node-gyp v7.1.2 bundled with npm [BUG] npx node-gyp@version runs the copy of node-gyp bundled with npm instead Nov 14, 2021
@fritzy fritzy added the cmd:exec related to `npx` label Jul 25, 2022
@wraithgar
Copy link
Member

This should be fixed as of npm@8.16.0

~/D/n/s/npx $ npx node-gyp@9 --version
v9.0.0
~/D/n/s/npx $ npx node-gyp@8 --version
Need to install the following packages:
  node-gyp@8.4.1
Ok to proceed? (y) 
v8.4.1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing cmd:exec related to `npx` Priority 2 secondary priority issue Release 7.x work is associated with a specific npm 7 release
Projects
None yet
Development

No branches or pull requests

5 participants