somethig wrong with npx Command failed: C:\“Program Files”\nodejs\node.exe
bluelovers opened this issue · comments
Just ran into this, too. Looks like npx
forgets to properly quote paths. Which is in itself a bit odd because no path issues should be necessary, just calling node
without any absolute path as process command should auto-resolve since it adds itself to the PATH during Windows installation, and running npm
is a matter of issuing npm.cmd
rather than npm
on the win32
platform (which is a misnomer and simply what Node calls windows architectures)
Running into the same thing here:
λ npx --help
Command failed: C:\"Program Files"\nodejs\node.exe C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js config get cache --parseable
module.js:491
throw err;
^
Error: Cannot find module 'C:\Program'
Might be worth bisecting this against previous versions of npx
, since this seems to be a recent issue.
I'm pretty sure this is happening because different Windows shells require different types of path escapes -- on Windows, npx uses CMD-style escapes, for example.
I use cmd
exclusively, given that powershell does not support "standard" shell syntax (like &&
to chain commands)
Got the same issue, with Git Bash on Win10.
This issue should be fixed in the latest npx (at least it was for me), which is not included in the latest nodejs installer. You can manually update/install npx
globally (npm install -g npx@latest
) to get the fix
@rossipedia you mean it's fixed on master, rather than 9.6.0? (there is no tag newer than that, and that's the latest version npm knows about)
Hmmmm npx@latest
fixed it for me. There may still be an issue then.
Also still having this issue on npx@latest
on Windows 10 Powershell. Here's a brief interaction I had with @npm_support on it a few versions back: https://twitter.com/noahdleigh/status/890355025104556032
Behavior hasn't changed on Node 8.4.0
, npm 5.4.1
, npx 9.6.0
When I looked into it, it seems as though path quoting is performed incorrectly on Windows. Instead of quoting each path element (eg: C:\"Program Files"\nodejs
), if there are any spaces the entire path needs to be quoted (ie: "C:\Program Files\nodejs"
).
@noahleigh If you are using Node 8.4.0 or newer, it falls to installed npx, which is npx 9.2.1.
I just deleted the npx files in the node folder for this to work.
tbh I probably need help here. I've spent time messing around with different escape methods, and they seem to vary by situation :\
@zkat latest version seems to run fine. Did you find bugs in Windows? Or with the fix for Windows something else got broken?
@zkat I'll try my hand at a PR here this weekend, I think I remember where the problematic method is
@michaeljota I deleted npx
and npx.cmd
from C:\Program Files\nodejs
and now it's using the updated 9.6.0 instead of 9.2.1!
PS C:\Users\noahleigh> npx -v
9.6.0
PS C:\Users\noahleigh> npx cowsay hey
npx: installed 9 in 3.627s
C:\Users\noahleigh\AppData\Roaming\npm-cache\_npx\4696\node_modules\cowsay\cli.js
_____
< hey >
-----
\ ^__^
\ (oo)\_______
(__)\ )\/\
||----w |
|| ||
Why would node fail to use the updated version even after npm install npx@latest -g
?
Because, as it does when updating npm
in that way, Node will always lookup first in the node folder, and then in the modules folder. 😄. At least, in Windows it works that way.
A bit more on that:
When nodejs is installed, the installation folder (eg: C:\Program Files\nodejs
) is added to the system %PATH%
environment variable.
However, your npm installation folder's bin directory %APPDATA%\bin
is added to your user's %PATH%
environment variable (since %APPDATAT%
is essentially just %USERPROFILE%\AppData\Roaming
).
Now here's the part where it breaks: in Windows, to get the final %PATH%
value, the user's variable is appended to the system variable, which means that the nodejs installation folder comes before the npm bin folder, whiiiiiich means that the installed np[mx]
will always be given preference over the one installed via npm install --global
.
I've personally fixed it by removing %PROGRAMFILES%\nodejs
from my system path, and adding it to my user path after the %APPDATA%\npm
entry.
@rossipedia Why does the nodejs installer put npm
stuff in the Program Files folder if the "real" and updated versions live in App Data? Why not just keep the executables in there exclusively?
Relevant nodejs issue: nodejs/node#15095
@noahleigh workaround to manually clean out 9.2.1
files worked for me. Curiously (and to my surprise) running cd C:\"Program Files"\nodejs\
in PowerShell works as expected, meaning it actually changes cwd to that folder. Per @rossipedia point, I think npx
should use whatever version of npm
is globally installed. I think it's an important UX decision.
Deleting the files from Program Files, as @noahleigh suggested, and updating to 9.6.0 resolved the issue for me.
I think it is good follow npm
way to refer the current version for consistency since npx
shipped with node installer just like npm
. So npx
in C:\Program Files\nodejs
will 'redirect' to npx
in %USERPROFILE%\AppData\Roaming\npm
. Otherwise it will be harder for Windows user to update npx
for newly installed node.
Deleting the files from Program Files, as @noahleigh suggested, and updating to 9.6.0 resolved the issue for me also.
npm
does not refer the current version in the way you describe. In deed, it refers to the current version the way npx
install in nodejs
folder does. That's why tools like npm-windows-upgrade exists.
@rossipedia your solution works perfectly
I got a similar error in an npm script and fixed by using the 8.3 ntfs filesystem shortname.
You can retrieve the shortname by "dir /x"
PROGRA~1
e.g.: "c:\PROGRA~1\7-Zip\7z.exe"