0

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?

user3217883
  • 1,216
  • 4
  • 38
  • 65

3 Answers3

0

You may need to run

$ npm config set user root

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

richytong
  • 2,387
  • 1
  • 10
  • 21
0

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.

Alwaysblue
  • 9,948
  • 38
  • 121
  • 210
Fifth Cloud
  • 110
  • 1
  • 9
  • During my attempt to "remove all traces of node" from my box, I also removed the node_modules folder in my React project. Later when I tried to get it back with "npm install" it failed. Instead "yarn install" worked. – user3217883 May 31 '20 at 16:50
  • Although I accepted this answer because after jumping through all the hoops defined by the "answer" link, and all the sub links on it, I was able to FINALLY get "npm run build" to work. Then I went back to Jenkins and did a "Build Now" and it gave the same damn error again. Then I went back to the folder and issued the command myself and indeed, got the same "react-scripts: Permission denied" error all over again! – user3217883 May 31 '20 at 17:08
  • I am rather new to stackoverflow as responding to messages and I didn't see this until now. Apologies on the delay. Seems you're still having trouble. With my raspberry pi as long as I updated the environmental variables to point to the new npm which I put on my Documents folder it worked just fine. Never used sudo since I did this. I am guessing you have tried the environmental variables to point to the new folder? Could be mistaken, but from my understanding node_modules folder is what was already installed so that shouldn't be causing any problems. – Fifth Cloud Jun 03 '20 at 20:54
0

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.

user3217883
  • 1,216
  • 4
  • 38
  • 65