Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
595 views
in Technique[技术] by (71.8m points)

reactjs - How to stop permission when creating a new react app

I am using an ubuntu os and each time I try to create a new react app without adding sudo, I get this error:

Creating a new React app in /home/bunny/bunny.

Installing packages. This might take a couple of minutes.
Installing react, react-dom, and react-scripts with cra-template...

npm ERR! Unexpected end of JSON input while parsing near '...jUJStbKRw4Wj3LhB5a/JP'

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/bunny/.npm/_logs/2020-12-31T13_36_25_597Z-debug.log

Aborting installation.
  npm install --save --save-exact --loglevel error react react-dom react-scripts cra-template has failed.

Deleting generated file... package.json
Deleting bunny/ from /home/bunny
Done.

If I use sudo in creating the react app successfully, I would have to input my password everytime I want to save a changes made in a file, add a new folder or file or even delete files and I can only add new files from the terminal.

I have searched for a solution to this and the last thing I tried was changing the owner of the directory so I could modify or create an app without the sudo priviledges and I did this:

sudo chown -R bunny:staff '/home/bunny/.npm/'

This doesn't seem to work either. I need help because inputing a password everytime and creating files from the terminal is now frustrating


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are two possibilities for this to fail.

First: You do not have npx or npm installed under your current user and it is rather installed to the root user (which is what sudo does - elevates you to a root user).

Second: You do not own the directory /home/bunny/bunny/.

Now, if you have the first issue then that could cause the second issue too as it would create the project directory under root user, which means you will not be able to create, delete files without sudo privileges. This seems highly likely because you cannot run npx create-react-app in the first place. So try running,

sudo chown -R $(whoami) ~/.npm

If you still face issues, I have found a similar question which has been answered - check it out here.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...