Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm sitting my react environment and I get this error.

New react installation. npm --version is running correctly but still :

npm ERR! code ENOLOCAL

npm ERR! Could not install from "Ibrahi\AppData\Roaming\npm-cache_npx\8992" as it does not contain a package.json file.

How do I fix this?

like image 347
Mohammed Amin Ibrahim Avatar asked Sep 01 '19 16:09

Mohammed Amin Ibrahim


4 Answers

I faced same issue, problem was due to space in my user name i.e. FirstName LastName and issue is with npx. I applied following fix and everything worked just fine

npm config set cache C:\tmp\nodejs\npm-cache --global

Source: https://github.com/zkat/npx/issues/146

like image 92
Bhupender Keswani Avatar answered Oct 08 '22 02:10

Bhupender Keswani


Many thanks to Bhupender for providing the github link!

A summary of the best answers there, for those, like me, coming late to the party:

Find the windows short name for your user directory...

cd C:\Users
dir /x

Then edit the npm cache location to use the windows short name.

e.g. "C:\Users\HP User" is also "C:\Users\HPUSER~1" so the following command resolves the problem...

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

This has the advantage of avoiding having to install create react app locally.

like image 44
sonelle Avatar answered Oct 08 '22 04:10

sonelle


Late to the party but I was also facing the same issue so what I did is

  1. Step 1: Open the Terminal as an Admin and run the following command first npm install -g create-react-app to get around the npx issue.
  2. After step 1 run this command:- npx create-react-app my-first-app hope so it'll help you.
like image 7
Waqas Hafeez Avatar answered Oct 08 '22 04:10

Waqas Hafeez


This happens when you have a space in your path. To fix it follow these steps:

  1. run npm config edit
  2. go to line where cache is: ; cache = 'C:\Users\FIRSTNAME LASTNAME\AppData\Roaming\npm-cache'
  3. replace the space between firstname and lastname with ~1
  4. remove ; at the beginning of the line
  5. run yarn

Just to make sure you've got it, the line should look like this:

cache = 'C:\Users\FIRSTNAME~1LASTNAME\AppData\Roaming\npm-cache

like image 3
Cata Hotea Avatar answered Oct 08 '22 02:10

Cata Hotea