why does "npm run build" produce error "react-scripts Permission denied"? - node.js

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.

Related

Error "Permission denied" after execute npm install

After executing npm install, occurs following error:
npm ERR! code 127
npm ERR! path /var/www/html/node_modules/core-js
npm ERR! command failed
npm ERR! command sh -c node -e "try{require('./postinstall')}catch(e){}"
npm ERR! sh: 1: node: Permission denied
I'm executing command as a root on Docker. I tried to set npm config set user 0 and npm config set unsafe-perm true but nothing changed.
I changed files ownership to root, and after that everything work.
chown -R root:root .
This is a common problem when you install packages using sudo. That's why you shouldn't install any package using sudo keyword.
The solution: Delete node_modules folder. If it says that you don't have permission then delete it directly from folder (not from IDE) or through the terminal.
After that install your packages again. This time only npm i without sudo.

Unable to run npm command "Error: Command failed: npm run start"

I am trying to run a npx command on my M1 MacBook but I keep getting the same error. I already installed node.js and npm so that I could run this command:
npx #mondaydotcomorg/monday-cli scaffold run ./ quickstart-react
However, when I run this command the output is:
> Repository was downloaded successfully
> Copying the directory
> Installing packages. It can take a few moments
> Node modules were installed successfully
> Running the project
Error: Command failed: npm run start
at ChildProcess.exithandler (node:child_process:389:12)
at ChildProcess.emit (node:events:513:28)
at maybeClose (node:internal/child_process:1091:16)
at Socket.<anonymous> (node:internal/child_process:449:11)
at Socket.emit (node:events:513:28)
at Pipe.<anonymous> (node:net:757:14) {
code: 1,
killed: false,
signal: null,
cmd: 'npm run start'
}
Before, I was getting an issue saying sh: concurrently: command not found and kill-port: command not found so I installed concurrently and kill-port using npm, which removed this error messages. However, now I get the output above. I installed node.js again and updated npm version to latest version, but no change. Any suggestions on how to fix this?
Edit: I found this link that is a solution to my exact problem. (https://community.monday.com/t/monday-cli-seems-not-to-work-on-apple-m1/36745). I ran npm install kill-port and ran npm upgrade and both executed correctly. However, when I try to run npm run start command by itself, this is my output:
npm ERR! Missing script: "start"
npm ERR!
npm ERR! Did you mean one of these?
npm ERR! npm star # Mark your favorite packages
npm ERR! npm stars # View packages marked as favorites
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR! npm run
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/mattspc/.npm/_logs/2022-07-18T21_08_52_459Z-debug-0.log
I think I need to find my destination folder and cd to it, then run npm run start within that folder. Any advice on how to locate it?
Finally figured out an answer to my own question. The main issue was my npm version and node.js version.
To get the latest stable version of npm, run this command in terminal npm install -g npm#latest and make sure you download the correct node.js version (this one is for Apple Silicon Chip/M1, select the option on the left). Then, run nvm use --lts command in terminal to make sure you are using the correct and most stable node.js version. Finally, look in the main directory (firstnamelastname folder on Mac) and delete the quickstart-react folder if it already exists. Then, run npx #mondaydotcomorg/monday-cli scaffold run ./ quickstart-react in terminal (if there is an error message, quit terminal and reopen it, then continue with the next step). You need to run the next part locally, so do cd quickstart-react, then npm run start and it should work. If there is any error message and it says something like sh: kill-port: command not found you need to install that specific dependency within the quickstart-react folder, so search up "npm install kill-port" or "npm install ____" depending on the error, quit and reopen terminal, do cd quickstart-react and run those install commands inside the quickstart-react folder. Should work after that.
If this doesn't work try using this link (https://community.monday.com/t/problem-to-setup-development-environment-quick-start-guide-with-cli/9422) that shows how to manually do this (this didn't work for me however).

Your cache folder contains root-owned files

Trying to run npm ci on a git deployment branch for my website but receiving the following error;
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /home/storm/.npm
npm ERR! errno -13
npm ERR!
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 1010:1010 "/home/storm/.npm"
I tried running the command it suggests but this doesn't work because there's no such file or directory of "/home/storm/.npm"
I can't find any answers online! Please help
There are multiple ways to solve the described issue. It depends on how you run npm.
Option 1:
Adapt the access rights on the npm cache files / folder. Just run the suggested command where 'storm' is your user name and '1010' are your user ID and group ID. (User ID and group ID sometimes differ.)
sudo chown -R 1010:1010 "/home/storm/.npm"
Option 2:
Remove the npm cache by running the following command:
sudo npm cache clean --force
Option 3:
Instruct npm to user another directory for caching (avoid using the default npm cache folder). Run the following command before running npm.
export npm_config_cache=/path/to/cache
In my case I ran yarn / npm in a CI/CD pipeline on a Jenkins agent and faced the same issue. Option 3 worked for me. I adapted my pipeline and replaced the command
gradle testAndCoverageWithYarn
with
export npm_config_cache=npm-cache && gradle testAndCoverageWithYarn
(The gradle task testAndCoverageWithYarn calls yarn / npm.)
I had this issue and this command worked for me:
sudo npm cache clean --force
If this issue sill occured try :
sudo chown -R 1010:1010 "/home/storm/.npm"
Good Luck ;-) I hope it works for You! Watch out for typos ..

Jenkins build issue - npm ERR! Your cache folder contains root-owned files

I am trying to build a small node app on my Jenkins pipeline, which is running in a virtual machine. cross this error:
+ npm install
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /.npm
npm ERR! errno EACCES
npm ERR!
npm ERR! Your cache folder contains root-owned files, due to a bug in
npm ERR! previous versions of npm which has since been addressed.
npm ERR!
npm ERR! To permanently fix this problem, please run:
npm ERR! sudo chown -R 111:120 "/.npm"
Running sudo chown -R 111:120 "/.npm" doesn`t help since it says:
chown: cannot access '/.npm': No such file or directory
And, as per my understanding, runs in a local context, when the problem is actually from the container perspective. I`ve tried to add the command above on my Docker and Jenkinsfile as well, to no avail. Below is my public repo:
Node app deploy on github
npm install --cache=".YourCustomCacheDirectoryName"
works perfectly fine, reason for this is your docker user isn't allowed to write in / ( root directory )
its not that a directory already exist at /.npm its that, your script is trying to create a directory at / which is not accessible for your user
you can either put
agent {
docker {
image 'node:latest'
args '-u root:root'
}
}
or just tell npm to use your custom cache directory
I had the same issue and fixed it by setting the npm cache directory to ENV variable in Dockerfile.
Add this to Dockerfile:
ENV npm_config_cache /home/node/app/.npm
As far as I can remember ,just updating npm version and deleting the whole project did the trick.

Error given in react-native when npm start

I am using
Node - v10.6.0
Npm version -4.6.1
When i tried to execute the commad npm start under my project folder, it is giving an error
my_app#0.1.0 start /mnt/E/react_native/my_app
react-native-scripts start
sh: 1: react-native-scripts: Permission denied
npm ERR! code ELIFECYCLE
npm ERR! errno 126
npm ERR! my_app#0.1.0 start:react-native-scripts start
npm ERR! Exit status 126
npm ERR!
npm ERR! Failed at the my_app#0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
Please help to rectify the issue
I think you are running your code on MAC. If yes then please try running below command:
sudo chown -R username:groupname directory
where "username" is your current user name, "groupname" is your primary group and "directory" is your project directory path.
Afterwards remove node_modules folder and try below commands:
npm install
npm start
I encountered the same issue, Surprisingly it works fine in Windows but failed in Linux giving the same error. Follow below step to resolve this issue.
you need to change package.json file inside your project folder like below instead of default value of "start": "react-scripts start"
"scripts": {
"start": "node ./node_modules/react-scripts/bin/react-scripts.js start" }
Try running:
sudo sysctl -w fs.inotify.max_user_instances=1024
sudo sysctl -w fs.inotify.max_user_watches=12288
before
npm start
This will temporarily increase the number of files that the development server is able to monitor for changes. This solution is specific for Ubuntu/Linux - the macOS equivalent is "kern.maxfiles" and "kern.maxfilesperproc"
If you haven't installed webpack-dev-server please do it by issuing the below command
npm install -g webpack webpack-dev-server
In case if you have already done it, try deleting your node_modules directory and run a fresh npm install before you execute your react-native-scripts start command.
Hope this helps.
You may not have necessary permissions, so you see:
sh: 1: react-native-scripts: Permission denied
Try starting it with :
sudo react-native-scripts start
I was having this issue. It was running after executing sudo chmod -R 755 .
I solved such a problem by making sure that my react-script binary was executable.
$ chmod +x node_modules/.bin/react-scripts

Resources