-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
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
cli/workspaces/config/lib/set-envs.js
Line 106 in 4689ae4
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