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

Running npx globally does not work on Windows when the user folder patch contains a space #146

Closed
GrimzEcho opened this issue Jan 3, 2018 · 24 comments

Comments

@GrimzEcho
Copy link

GrimzEcho commented Jan 3, 2018

This may be related to issue #110, but I believe it is separate. However, I have tried the various fixes suggested in that thread.

When running npx (with any arguments, but -v is easiest to test) from the global install folder, the following error is produced.

npm ERR! code ENOLOCAL
npm ERR! Could not install from "Echo\AppData\Roaming\npm-cache\_npx\14184" as it does not contain a package.json file.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\Grim Echo\AppData\Roaming\npm-cache\_logs\2018-01-03T00_26_34_241Z-debug.log

It seems that npx is not properly escaping any spaces contained in the npm config prefix variable.

$ npm config list
metrics-registry = "https://registry.npmjs.org/"
scope = ""
user-agent = "npm/5.5.1 node/v9.3.0 win32 x64"

; userconfig C:\Users\Grim Echo\.npmrc
prefix = "C:\\Users\\Grim Echo\\AppData\\Roaming\\npm"

; builtin config undefined

; node bin location = C:\Program Files\nodejs\node.exe
; cwd = D:\gdrive\Projects\Web\React\test_1
; HOME = C:\Users\Grim Echo
; "npm config ls -l" to show all defaults.

The full error log file

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'install',
1 verbose cli   'prefix@latest',
1 verbose cli   '--global',
1 verbose cli   '--prefix',
1 verbose cli   'C:\\Users\\Grim',
1 verbose cli   'Echo\\AppData\\Roaming\\npm-cache\\_npx\\16608',
1 verbose cli   '--loglevel',
1 verbose cli   'error',
1 verbose cli   '--json' ]
2 info using npm@5.5.1
3 info using node@v9.3.0
4 verbose npm-session 276140a6271ea49d
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 silly fetchPackageMetaData error for file:Echo\AppData\Roaming\npm-cache\_npx\16608 Could not install from "Echo\AppData\Roaming\npm-cache\_npx\16608" as it does not contain a package.json file.
8 http fetch GET 200 https://registry.npmjs.org/prefix 46ms (from cache)
9 silly pacote tag manifest for prefix@latest fetched in 87ms
10 verbose stack Error: ENOENT: no such file or directory, open 'D:\gdrive\Projects\Web\React\test_1\Echo\AppData\Roaming\npm-cache\_npx\16608\package.json'
11 verbose cwd D:\gdrive\Projects\Web\React\test_1
12 verbose Windows_NT 10.0.16299
13 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install" "prefix@latest" "--global" "--prefix" "C:\\Users\\Grim" "Echo\\AppData\\Roaming\\npm-cache\\_npx\\16608" "--loglevel" "error" "--json"
14 verbose node v9.3.0
15 verbose npm  v5.5.1
16 error code ENOLOCAL
17 error Could not install from "Echo\AppData\Roaming\npm-cache\_npx\16608" as it does not contain a package.json file.
18 verbose exit [ 1, true ]

Note lines 1, 13, and 17.

Notice how the path is split on lines 1, and how the space is improperly escaped on line 13. The entire path needs to be in a string, but npx seems to be splitting it into two strings.

This issue seems specific to npx, as other npm commands seem to use the prefix directory correctly.

This is running npx 9.6.0 on node 9.3.0 on Windows 10.

The issue does not happen when the user directory contains no spaces, or when running npx locally from within a project folder.

@valuka
Copy link

valuka commented Feb 20, 2018

I have exactly same issue with npx due to space in path.
npm works fine.

@ArthurAttout
Copy link

Any fix for this ?

@rivajunior
Copy link

I have found a workaround.
First you can rename your user on Windows, but it don't rename the user folder yet.
The commands to do this is: Windows + R then type control userpasswords2. Now click on your user and after click on properties and rename your user name.

After do this, comes the hard part:

Press Windows + X and open Windows Power Shell as Administrator.
After this, type net user administrator \active:yes. (the name administrator can change with your language system)
Now you can exit from your user and log-in into Administrator user.
Go to folder C:\Users\Your User Name, and rename for the name that you want.

Be careful with this part:

Press Windows + R to open regedit
Go to HKEY_LOCAL_MACHINE\Software\Microsoft\Windows NT\CurrentVersion\ProfileList\. finde your user and rename for the new name.

you can find that steps here.

For me, this was worked fine

@PhiLhoSoft
Copy link

OK, I was excited to see this npx, it looked very interesting, but this bug makes it just unusable. Too bad.
Renaming the user name is not an option for me, alas.

@keerotic
Copy link

you can change "npm-cache" folder to anothor path,
using command :
"npm config set cache C:\tmp\nodejs\npm-cache --global"

@keerotic
Copy link

keerotic commented Apr 24, 2018

if you want to use current path that has space in username "C:\Users\Firstname Lastname\AppData\Roaming\npm-cache"
you can replace the string after space with "~1"

npm config set cache "C:\Users\Firstname~1\AppData\Roaming\npm-cache" --global

@zkat
Copy link
Owner

zkat commented May 4, 2018

This is a duplicate of #100

@philson-philip
Copy link

The above error is due the white space contain in your username of PC. The command npx create-react-app doesn't work in this situation and shows error. I have fixed the error and created my first react app.
https://github.com/philson-philip/react-skills
Check the above link for solving the problem and creating your first app with react. Commands are detailed in the README.md file.

@jokerdrake
Copy link

@citoreek Great, this fixes the problem I am having.Thanks!

@aliyankhan
Copy link

Done fixing both npm and npx.
Take a look at this:
https://www.youtube.com/watch?v=TkAwSMxfezs

@sudhir600
Copy link

I did the all changes as described by @citoreek. after that i am getting new error-

22 error 404 'create-nuxt-add@latest' is not in the npm registry.
23 error 404 Your package name is not valid, because
24 error 404 1. name can only contain URL-friendly characters
25 error 404 Note that you can also install from a
26 error 404 tarball, folder, http url, or git url.
27 verbose exit [ 1, true ]

Note sure what should i do

@edisgreat
Copy link

I had a similar error on Ubuntu WSL on Windows 10, and tried just dropping npx, so calling just

create-react-app tutorial-react

and it seems to work now

@g8up
Copy link

g8up commented Jan 16, 2019

On Windows, I fixed it in #146 (comment) 's way:

  1. run npm config edit to edit your config
  2. change cache path,e.g.
    from cache=D:\program file\npm-cache to cache=D:\progra~1\npm-cache

@demiro
Copy link

demiro commented Feb 8, 2019

2. change cache path,e.g.
from cache=D:\program file\npm-cache to cache=D:\program~1\npm-cache

don't forget to remove the ';' at the beginning of the line

@gijswijs
Copy link

you can replace the string after space with "~1"

@citoreek It's a bit more complicated. You remove all the spaces from the folder name, then you take the first 6 characters of the folder name and postfix it with ~1. Officialy, you should also uppercase it, but I found it doesn't make a difference.

So the full path of my folder was:
C:\Users\Gijs van Dam\AppData\Roaming\npm-cache
the path with the short folder name is:
C:\Users\GIJSVA~1\AppData\Roaming\npm-cache

If you want to be sure, you can use
dir /x in cmd
or
cmd /c dir /x in powershell to see the short file and folder names inside a folder.

@jonas-thuvesson-winberg
Copy link

Why is this issue closed?

@killian-coder
Copy link

I download the latest version of node
run this npm config edit command
removed the comma (;) on this cache=C:\Users\Killian C\AppData\Roaming\npm-cache
and the space in between killian C saved and run

@nkb-bd
Copy link

nkb-bd commented Mar 27, 2019

Thanks killian-coder , but it should be fixed soon

@dannyLister
Copy link

you can replace the string after space with "~1"

@citoreek It's a bit more complicated. You remove all the spaces from the folder name, then you take the first 6 characters of the folder name and postfix it with ~1. Officialy, you should also uppercase it, but I found it doesn't make a difference.

So the full path of my folder was:
C:\Users\Gijs van Dam\AppData\Roaming\npm-cache
the path with the short folder name is:
C:\Users\GIJSVA~1\AppData\Roaming\npm-cache

If you want to be sure, you can use
dir /x in cmd
or
cmd /c dir /x in powershell to see the short file and folder names inside a folder.

Thank you for this. No one explained before that you only need the first six characters. If you have any more characters than 6 then it goes and creates a new folder.

@ZeCarlosCoutinho
Copy link

you can replace the string after space with "~1"

@citoreek It's a bit more complicated. You remove all the spaces from the folder name, then you take the first 6 characters of the folder name and postfix it with ~1. Officialy, you should also uppercase it, but I found it doesn't make a difference.
So the full path of my folder was:
C:\Users\Gijs van Dam\AppData\Roaming\npm-cache
the path with the short folder name is:
C:\Users\GIJSVA~1\AppData\Roaming\npm-cache
If you want to be sure, you can use
dir /x in cmd
or
cmd /c dir /x in powershell to see the short file and folder names inside a folder.

Thank you for this. No one explained before that you only need the first six characters. If you have any more characters than 6 then it goes and creates a new folder.

It is the first 6 characters that have an entry in the ASCII table. If you have strange characters, they also don't count for the short folder name.
For example, a folder name like "André Silva", would be "ANDRSI~1" in the short name version, because it cuts the "é" and the space.

@jwmcpeak
Copy link

Why is this issue closed?

I'm wondering the same thing. The issue is not resolved.

@Wavez
Copy link

Wavez commented Jun 3, 2019

if you want to use current path that has space in username "C:\Users\Firstname Lastname\AppData\Roaming\npm-cache"
you can replace the string after space with "~1"

npm config set cache "C:\Users\Firstname~1\AppData\Roaming\npm-cache" --global

to get the exact tilde short path,

cd C:\Users
dir /x

Then copy the shown username and paste in the above command

@gatoenano
Copy link

Another simple fix for spaces problem would be
npx --npm="C:\PROGRA~1\nodejs\node_modules\npm\bin\npm-cli.js" -p <package you want to install>

@MP-STARK
Copy link

MP-STARK commented Jul 5, 2019

you can change "npm-cache" folder to anothor path,
using command :
"npm config set cache C:\tmp\nodejs\npm-cache --global"

the best answer....it really works!!! thank you!!

krazyito65 referenced this issue in LanikSJ/slack-dark-mode Feb 12, 2020
* Temporarily update NPM cache when a space in path exists.
FIXES #238

* Move chace check after npx check
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests