Error "Your cache folder contains root-owned files, due to a bug in previous versions of npm" while "npx create-react-app example_app"
Solution 1
This worked for me:
sudo npm cache clean --force
Solution 2
This is what helped me after going through the above answers. I hope it helps someone else too. After re-reading the npm error prompt, I adjusted the provided command to include the .npm path given in the error message. Below is a copy of my original error messages.
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /home/vagrant/.npm-global/lib/node_modules
npm ERR! errno -13
npm ERR!
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 900:900 "/home/vagrant/.npm"
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vagrant/.npm/_logs/2020-07-09T16_43_35_046Z-debug.log
[ExecStack] Exit code 243 Time 01:03
[error] Executing target-hook frontend-reqs failed.
[error] Command
source:build:frontend-reqs
exited with code 1.
Instead of using sudo chown -R 900:900 "/home/vagrant/.npm", I used sudo chown -R 900:900 "/home/vagrant/.npm-global". After that, I was able to use the previous command that caused the error with no issues.
Solution 3
Try sudo chown -R 1000:1000 "/home/shubham/.npm"
Solution 4
I had the same issue and several others while trying to update my npm packages. I will be honest I do not have enough knowledge of package handlers or why this fixed my situation, but I believe my version of npm and npx were causing the issues. I had errors immediately trying to install npx, node and create-react-app with my old and out of date version of npm.
I could not run npm install npx -g
without --force
. Once I did that I also ran npm install npm -g --force
. After this I could already tell things were different.
After npm and npx were completely overwritten, I ran npm install node -g
and npm install create-react-app -g
without any weird problems. I created a new react app and started it error free.
(I also ran the cache command before all of this. sudo npm cache clean --force
which I am unsure if it helped).
Solution 5
I had to do both the root folder and the root/.npm
sudo chown -R 1001:1001 "/root"
sudo chown -R 1001:1001 "/root/.npm"
Related videos on Youtube
Anurag Srivastava
Greetings, a 1x Engineer here. Former UI / UX developer at Amdocs Currently freelancing on Upwork and Guru. Tinkering sometimes on Codepen and JSFiddle Learning Blender. Usually browsing these tags: javascript css reactjs three.js angularjs jquery
Updated on July 09, 2022Comments
-
Anurag Srivastava almost 2 years
When I was trying to create a new react app using
npx create-react-app example_app
, I get this error[Your cache folder contains root-owned files, due to a bug in previous versions of npm which has since been addressed sudo chown -R 0:0 "/root/.npm"]
I even tried to re-install
create-react-app
again usingnpm i create-react-app
, it is giving the same kind of error.I assume after searching about it that it is due to some permissions issue. My current user doesn't have permission to
/home/shubham/.npm
whereshubham
is my username, but I am not so sure about this.I have tried to solve this error using
chown
command assudo chown -R <username>:<groupname> /home/shubham/.npm"
where
<username>
isShubham
and<groupame>
is1000
, but it is still not working.Request people to help me out. If you need any more information, let me know.
-
kfir88 over 4 yearsi have same error here. hope somebody have solution!
-
George S almost 4 yearsi am also having this same issue
-
Fabien Snauwaert about 2 yearsHad the same thing inside Docker. Merely restarting the container fixed it.
-
-
Admin over 4 yearsTried with this command, still getting the same error. [ npm ERR! Your cache folder contains root-owned files, due to a bug in previous versions of npm which has since been addressed. To permanently fix this problem, please run: sudo chown -R 0:0 "/home/shubham/.npm" ]
-
Anurag Srivastava over 4 yearsDid you also clean npm cache?
-
Admin over 4 yearsI have cleaned npm cache using "npm cache clean --force" as "npm cache clean" was giving error "As of npm@5, the npm cache self-heals". But now when i tried to run "npx create-react-app example_app”, it gets stucked while creating the app in middle of progress bar.
-
Admin about 4 yearsThanks for commenting. I tried with the given command, still getting same error.
-
Admin about 4 yearsThanks for commenting. I tried with the given command, still getting same error
-
Admin about 4 yearsThanks for commenting. I tried with the given command, still getting same error
-
Joseph Khella about 4 yearsthis is not an answer to the question, just try commenting through it, I think he already tried that
-
Admin about 4 yearsRight,I have already tried the same. Still not able to resolve it.