Skip to content
This repository has been archived by the owner on Jul 6, 2019. It is now read-only.

somethig wrong with npx Command failed: C:\“Program Files”\nodejs\node.exe #110

Closed
bluelovers opened this issue Aug 14, 2017 · 29 comments

Comments

@bluelovers
Copy link

my npx always show this error

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:487

20170814-082755_tavgg
20170814-082758_dyim1

@Pomax
Copy link

Pomax commented Aug 16, 2017

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)

@rossipedia
Copy link

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'

@Pomax
Copy link

Pomax commented Aug 17, 2017

Might be worth bisecting this against previous versions of npx, since this seems to be a recent issue.

@zkat
Copy link
Owner

zkat commented Aug 25, 2017

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.

@Pomax
Copy link

Pomax commented Aug 28, 2017

I use cmd exclusively, given that powershell does not support "standard" shell syntax (like && to chain commands)

@sylvainlap
Copy link

Got the same issue, with Git Bash on Win10.

@rossipedia
Copy link

rossipedia commented Aug 30, 2017

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

@Pomax
Copy link

Pomax commented Aug 30, 2017

@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)

@rossipedia
Copy link

Hmmmm npx@latest fixed it for me. There may still be an issue then.

@noelleleigh
Copy link
Contributor

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

@rossipedia
Copy link

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").

@michaeljota
Copy link

@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.

@zkat zkat added the bug label Sep 15, 2017
@zkat
Copy link
Owner

zkat commented Sep 15, 2017

tbh I probably need help here. I've spent time messing around with different escape methods, and they seem to vary by situation :\

@michaeljota
Copy link

michaeljota commented Sep 15, 2017

@zkat latest version seems to run fine. Did you find bugs in Windows? Or with the fix for Windows something else got broken?

@zkat zkat added the windows label Sep 15, 2017
@rossipedia
Copy link

@zkat I'll try my hand at a PR here this weekend, I think I remember where the problematic method is

@noelleleigh
Copy link
Contributor

@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?

@michaeljota
Copy link

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.

@rossipedia
Copy link

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.

@noelleleigh
Copy link
Contributor

@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?

@michaeljota
Copy link

michaeljota commented Sep 16, 2017 via email

@noelleleigh
Copy link
Contributor

Relevant nodejs issue: nodejs/node#15095

@duluca
Copy link

duluca commented Sep 18, 2017

@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.

@kim3er
Copy link

kim3er commented Sep 19, 2017

Deleting the files from Program Files, as @noahleigh suggested, and updating to 9.6.0 resolved the issue for me.

@CallMeLaNN
Copy link

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.

@michaeljota
Copy link

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.

@kedrzu
Copy link

kedrzu commented Oct 18, 2017

@rossipedia your solution works perfectly

@boxfoot
Copy link

boxfoot commented Nov 9, 2017

I'm getting a different error that also seems to be related to Windows path escaping. I'm running up-to-date npm and npx.

I'm also confused b/c it seems to be reporting two errors - a failure to mkdirp, and then the error handler seems unable to load npm.config...

image

Is this the same (or related?)

@mmueller013
Copy link

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"

@zkat
Copy link
Owner

zkat commented May 4, 2018

This is a duplicate of #100 and should be resolved by #181

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests