Error “Your cache folder contains root-owned files, due to a bug in previous versions of npm” while “npx create-react-app example_app”

末鹿安然 提交于 2020-05-26 15:09:22

问题


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 using npm 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 where shubham is my username, but I am not so sure about this.

I have tried to solve this error using chown command as

sudo chown -R <username>:<groupname> /home/shubham/.npm" 

where <username> is Shubham and <groupame> is 1000, but it is still not working.

Request people to help me out. If you need any more information, let me know.


回答1:


This worked for me:

sudo npm cache clean --force 



回答2:


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




回答3:


Try sudo chown -R 1000:1000 "/home/shubham/.npm"




回答4:


it work for me now!

what id did? (i'm not saying it's the best way to fix this. but that way is working for me. i'm still looking for the best explications for this issue)

  sudo rm -Rf /home/[YOUR_USER_NAME]/.npm-global/lib/node_modules/

and run your command again.

My explication is that it seem like something is corrupted in the node_modules's folder. as it's not risky to delete it i did it and it work now.




回答5:


It helped me: Remove and install npm again



来源:https://stackoverflow.com/questions/59437833/error-your-cache-folder-contains-root-owned-files-due-to-a-bug-in-previous-ver

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!