Is there an existing issue for this?
This issue exists in the latest npm version
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:
Is there an existing issue for this?
This issue exists in the latest npm version
Current Behavior
The env
npm_execpathcan be path ofnpxinstead ofnpmif the user runs a command withnpx, e.g.npx node -e "console.log(process.env.npm_execpath)", the output will be/path/to/npm/9.8.1/bin/npx-cli.jscli/workspaces/config/lib/set-envs.js
Line 106 in 4689ae4
I did not find the official definition for
npm_execpath, but I assume it should only be the path ofnpmbased its name, not the path ofnpx.Some popular libraries, e.g
npm-run-all, usingnpm_execpathand assuming it's the package manager path and addrunarg to it, so if you runnpx npm-run-all test, it is the same asnpx run testwhich will install a package calledrunand 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-scriptsExpected Behavior
npm_execpathshould always be set as the path ofnpm.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.jsEnvironment