7

OS: Windows
for creating react app using npx i've write the following command:

npx create-react-app myapp

it shows this error:

npm ERR! Could not install from "myusername\AppData\Roaming\npm-cache\_npx\19748" as it does not contain a package.json file.

How can i fix it?

Sarthak Bhagwat
  • 634
  • 1
  • 5
  • 13

3 Answers3

44

this error occurs usually when name of the PC contain a space like

mycomputer name

you should fix this by redefine your npm cache root There is a simple workaround to fix this problem. 8.3 DOS path format should be used. Open command prompt in administration mode then cd to C:\Users and run this command :

C:\Users>dir /x

and find the short path for your desired directory i.e. username let us say it is MYCOMP~1 (it's not always MYCOMP~1 ) try:

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

be careful for space character in the pc name you should use the one you got from command prompt instead and now use:

npx create-react-app myapp

happy coding!!!

Sarthak Bhagwat
  • 634
  • 1
  • 5
  • 13
11

I am late for the party but I had the same problem with name space in my PC directory. What I did to fix this problem was to:

  1. create empty folder in other location than C like on D directory named folder/npm-cache
  2. in terminal I run : npm config set cache "D:\name-cache\AppData\Roaming\npm-cache" --global
  3. If you still want to have it on your current path that has space in username

like "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

This answer was taken from from https://github.com/zkat/npx/issues/146.

Dharman
  • 30,962
  • 25
  • 85
  • 135
Magda
  • 211
  • 3
  • 3
0

Hy as they said above this error occurs usually when name of the PC contain a space like
step 1: navigate to C:\Users> and run C:\Users>dir /x enter image description here

The USERPC~1 is an alternative name for USER PC on my system. notice the space between USER and PC

step 2: Now run npm config set cache "C:\Users\USERPC~1\AppData\Roaming\npm-cache" --global if you have e.g. DAM SAM use DAMSAM~1

step 3: now run npm config edit. it will open a txt file, look for where your cache is and check if the path you ran above matches the one in the txt file enter image description here

step 4: if it matches save the file and run npx create-react-app.it will run. If not change the path manually to "C:\Users\USERPC~1\AppData\Roaming\npm-cache" as was in my case.

step 5: ensure you save the .txt file. then run npx create-react-app command