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] npm_execpath is set to the path of npx instead of npm #6662

Closed
2 tasks done
Zhangdroid opened this issue Jul 20, 2023 · 0 comments · Fixed by #6762
Closed
2 tasks done

[BUG] npm_execpath is set to the path of npx instead of npm #6662

Zhangdroid opened this issue Jul 20, 2023 · 0 comments · Fixed by #6762
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 9.x work is associated with a specific npm 9 release

Comments

@Zhangdroid
Copy link

Zhangdroid commented Jul 20, 2023

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

The env npm_execpath can be path of npx instead of npm if the user runs a command with npx, e.g. npx node -e "console.log(process.env.npm_execpath)", the output will be /path/to/npm/9.8.1/bin/npx-cli.js

env.npm_execpath = require.main.filename

I did not find the official definition for npm_execpath, but I assume it should only be the path of npm based its name, not the path of npx.

Some popular libraries, e.g npm-run-all, using npm_execpath and assuming it's the package manager path and add run arg to it, so if you run npx npm-run-all test, it is the same as npx run test which will install a package called run and throw errors.

Yarn also suggests use $npm_execpath run <name> which can cause the same problem: https://yarnpkg.com/advanced/rulebook#published-packages-should-avoid-using-npm-run-in-their-scripts

Expected Behavior

npm_execpath should always be set as the path of npm.

Steps To Reproduce

Run npx node -e "console.log(process.env.npm_execpath)"

The output will be /path/to/npm/9.8.1/bin/npx-cli.js

Environment

  • npm: 9.8.1
  • Node.js: 20.4.0
  • OS Name: MacOS
  • System Model Name: Macbook Pro
  • npm config:
n/a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Needs Triage needs review for next steps Release 9.x work is associated with a specific npm 9 release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant