简体   繁体   中英

why does “npm run build” produce error “react-scripts Permission denied”?

I'm on Ubuntu 18.04, logged in as root. The group:owner of /root/.npm is root:root, recursively, and all permissions are 777, recursively. If I cd to the React folder:

cd /var/lib/jenkins/workspace/MedAverter/medaverter-front

And set all permissions of that folder to 777, recursively and then run

npm run build

I get error:

[[1;34mINFO[m] Running 'npm run build' in /var/lib/jenkins/workspace/MedAverter/medaverter-front [[1;34mINFO[m] [[1;34mINFO[m] > medaverter-front@0.1.0 build /var/lib/jenkins/workspace/MedAverter/medaverter-front [[1;34mINFO[m] > react-scripts build [[1;34mINFO[m] [[1;31mERROR[m] sh: 1: react-scripts: Permission denied [[1;31mERROR[m] npm ERR; code ELIFECYCLE [[1;31mERROR[m] npm ERR. errno 126 [[1.31mERROR[m] npm ERR: medaverter-front@0.1.0 build: react-scripts build [[1;31mERROR[m] npm ERR; Exit status 126 [[1;31mERROR[m] npm ERR. [[1.31mERROR[m] npm ERR. Failed at the medaverter-front@0.1.0 build script.

I've been googling for a solution for hours with no luck. It builds fine under Windows 10. Suggestions?

You may need to run

$ npm config set user root

I ran into that issue once building from a node docker file

Since I am unable to comment.

Personally, I have followed this answer and chosen Solution 2.

After reading more about this you shouldn't be giving npm sudo/root permissions. You are putting way too much faith in the scripts. Rather update your npm by following that guide and you will no longer have that issue.

Did that for my raspberry pi.

I finally solved this problem. The solutions is shown here: "npm run build" = "react-scripts: Permission denied"

The main problem was that user jenkins was trying to run things owned by user root. So you need to do a

sudo chown -R jenkins medaverter-front

you also need to put sudo in front of the chmod as in

sudo chomod -R 777 medaverter-front

Even though I was logged in as root, somehow that was not enough. I don't understand why not but there were definitely some items whose permissions were not being changed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM