Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"npm run build" = "react-scripts: Permission denied"

I'm trying to deploy my working Windows 10 Spring-Boot/React app on Ubuntu 18.04 but keep getting "react-scripts: Permission denied" error despite numerous attempts to fix. Hopefully one of you react experts can spot what I'm doing wrong.

My package.json looks like this

{
  "name": "medaverter-front",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^4.2.4",
    "@testing-library/react": "^9.3.2",
    "@testing-library/user-event": "^7.1.2",
    "axios": "^0.19.2",
    "bootstrap": "^4.4.1",
    "react": "^16.13.0",
    "react-dom": "^16.13.0",
    "react-router-dom": "^5.1.2",
    "react-scripts": "3.4.0",
    "react-table-6": "^6.11.0",
    "react-validation": "^3.0.7",
    "reactstrap": "^6.5.0",
    "validator": "^12.2.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  }
}

I'm logged in as root and used nvm to install node and lts. I installed nvm like this:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.0/install.sh | bash

then did this:

nvm install node
nvm use node
nvm install --lts
nvm use --lts

Then I cd to /var/lib/jenkins/workspace/MedAverter/medaverter-front and install node_modules like this:

npm install -g

and then change the permissions to 777 recursively, like this:

chmod -R 777 node_modules

I also changed all the /root/.nvm permissions to 777 recursively, like this:

chmod -R 777 /root/.nvm

I can get it build once using

npm run build

but then I run a "Build Now" from Jenkins and it fails with the same

[[1;34mINFO[m] Running 'npm run build' in /var/lib/jenkins/workspace/MedAverter/medaverter-front
[[1;34mINFO[m] [[1;34mINFO[m] > [email protected] 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! [email protected] build: `react-scripts build` 
[[1;31mERROR[m] npm ERR! Exit status 126

Then I cd to /var/lib/jenkins/workspace/MedAverter/medaverter-front and run

npm run build

And also get the same error again:

> root@ubuntu-s-1vcpu-1gb-nyc1-01:/var/lib/jenkins/workspace/MedAverter/medaverter-front#
> npm run build
> 
> > [email protected] build /var/lib/jenkins/workspace/MedAverter/medaverter-front
> > react-scripts build
> 
> sh: 1: **react-scripts: Permission denied** npm ERR! code ELIFECYCLE
> npm ERR! errno 126 npm ERR! [email protected] build:
> `react-scripts build` npm ERR! Exit status 126

I've literally spent days trying to figure this out. Suggestions?

like image 244
user3217883 Avatar asked Jun 01 '20 20:06

user3217883


5 Answers

Solution 1:

I think you have react-script globally installed. so try this command

npm install react-scripts --save

and then run the application again.

Solution 2:

try this command

sudo chmod +x node_modules/.bin/react-scripts

and then run the application again.

Solution 3;

I think your npm not have permission. you can try to run by sudo

sudo npm run build

and you can fix this problem like this

Step 1:

check path of npm if you are using npm by

which npm

you will "/usr/local/bin/npm" this type of path

OR

check path of yarn if you are using yarn by

which yarn

you will "/usr/local/bin/npm" this type of path

Step 2:

give permission 777 to this path and try to run project

sudo chmod -R 777 /usr/local/bin/npm
like image 133
Muhammad Numan Avatar answered Oct 20 '22 23:10

Muhammad Numan


Solution for macOS

From the root of your project run:

chmod +x node_modules/.bin/react-scripts
like image 21
Chris Perry Avatar answered Oct 20 '22 22:10

Chris Perry


Instead of the default "start": "react-scripts start" specified in your package.json file, try changing it to the following and then try: "scripts": { "start": "node ./node_modules/react-scripts/bin/react-scripts.js start" }

like image 7
Technext Avatar answered Oct 20 '22 23:10

Technext


I had modified the permissions on the folders earlier and undid the changes. I believe that is it.

I just deleted the node_modules folder and reinstalled the dependencies with the yarn command.

sudo rm -rf node_modules
yarn
yarn start
like image 4
Samuel Terra Avatar answered Oct 21 '22 00:10

Samuel Terra


In my case it was giving at npm run. this is how i solved.

  1. rm -rf /node_modules
  2. npm i
  3. npm run android
like image 1
Ahsan Khan Avatar answered Oct 21 '22 00:10

Ahsan Khan