You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ npx node -e "console.log(3)"
sh: -c: line 0: syntax error near unexpected token `('
sh: -c: line 0: `node -e console.log(3)'
npm ERR! code 2
npm ERR! path /Users/rybickic/Developer/empty-dir
npm ERR! command failed
npm ERR! command sh -c node -e console.log(3)
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/rybickic/.npm/_logs/2020-12-24T08_25_37_431Z-debug.log
Expected Behavior:
$ npx node -e "console.log(3)"
3
Steps To Reproduce:
See commands above.
I've tried running this with several npm version combinations, and it appears to be a regression introduced in npm 7.1.0. That is, with the npm@7.0.15 the command succeeds (prints 3), but starting in npm@7.1.0 it fails. This was brought to my attention when I was updating to the latest node release (v15.5.0) two days ago via nvm, which updates npm to 7.3.0 (changelog).
Environment:
OS: macOS Catalina 10.15.7
Node: 15.5.0
npm: 7.3.0
The text was updated successfully, but these errors were encountered:
We were using it so that in a script, we could change the PATH environment variable to include the project's node_modules, and run commands from packages inside, e.g.:
My understanding is npx modifies the context a process runs in by automatically determining the right paths to add. If you omit the npx prefix, and ran node -e "console.log(process.env.PATH)" instead, the output value will not contain the project's node_modules, so some-command will fail (not be found).
We were using npx -c "echo $PATH" previously, but discovered this fails on Windows so we switched to the code above. For now, npx -c 'node -e "console.log(process.env.PATH)"' is another temporary solution we've found.
For the tool I am building, we don't want consumers to have to manually prefix commands with "npx" depending on whether it's an npm script or a python script etc. so that's why we are trying to set up the environment like this.
Current Behavior:
Expected Behavior:
Steps To Reproduce:
See commands above.
I've tried running this with several npm version combinations, and it appears to be a regression introduced in npm 7.1.0. That is, with the npm@7.0.15 the command succeeds (prints 3), but starting in npm@7.1.0 it fails. This was brought to my attention when I was updating to the latest node release (v15.5.0) two days ago via nvm, which updates npm to 7.3.0 (changelog).
Environment:
The text was updated successfully, but these errors were encountered: