npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules - javascript

Note: Due to security concerns, please don't use the marked solution but instead the highest voted one!
original question:
I am trying to install monaca with this command.
npm install -g monaca
But right after getting these errors:
npm WARN checkPermissions Missing write access to /usr/local/lib/node_modules
npm ERR! path /usr/local/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! { Error: EACCES: permission denied, access '/usr/local/lib/node_modules'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/usr/local/lib/node_modules\'',
npm ERR! errno: -13, npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/local/lib/node_modules' }
Any idea how to solve this problem?
Thank you

add following lines to ~/.bashrc after installing npm:
npm set prefix ~/.npm
PATH="$HOME/.npm/bin:$PATH"
PATH="./node_modules/.bin:$PATH"
Execute following line after changes:
source ~/.bashrc
and as mentioned by #contemplator avoid using sudo

This command will change the owner (chown) recursively (-R) for the current user in the specified directory
sudo chown -R $USER /usr/local/lib/node_modules

To all the warnings telling not to use sudo above, I'd add the following solution that worked pretty well for me while installing n, node version manager
sudo chown -R $USER /usr/local/lib/node_modules
This was taken from here: https://poopcode.com/missing-write-access-to-usr-local-lib-node-modules/
PS: for my specific use-case I also needed to run this one afterwards
sudo chown -R $USER /usr/local/bin/

Well, I used --save-dev and installed it not globally or using -g, the main problem occurs while you want it to write on default node_modules folder.
It solved my problem after 4 hours of checking multiple issues.
I even suggest you to use the npm init and make a package.json for a better dependency checking and then run npm install afterward. this video helps you for this https://www.youtube.com/watch?v=rTsz09zRuTU

Please dont use sudo.
I don't know the context of your environment, but I got the error on a server where Plesk was running.
Maybe the following command will help (via SSH) to check the permissions:
plesk repair fs example.com.
Manual: https://docs.plesk.com/en-US/12.5/administrator-guide/plesk-administration/plesk-repair-utility/plesk-repair-utility-file-system.74668/
In my case the node_modules folder was copied via FTP and therefore it had the wrong corrections. If necessary, you can remove this and install it via Plesk using the Npm installation button.
Info: The button only appears if the document contains a package.json with information.

it is very simple
you can use
sudo npm install -g kazam
or
su -
then
npm install -g kazam
explenation
su -
makes you as root ,who have permission to read , write and delete in all users
click here for the screen shot showing the error and the solution in the update of npm
this is for ubuntu i don't know is it work for other os

An inadvisable way to fix the issue would be to use sudo:
sudo npm install -g monaca
However it would be better to find a way around this without using sudo.
npm install -g less does not work

Related

docker build problem with npm install Error: Invalid response body while trying to fetch https://registry.npmjs.org Socket timeout

docker build problem with npm install and it's only inside docker I've tested. it's working on my os perfectly
Error
Step 6/8 : RUN npm cache clear --force && npm install --legacy-peer-deps
---> Running in 361c2a07ac22
npm WARN using --force Recommended protections disabled.
npm notice
npm notice New minor version of npm available! 8.4.1 -> 8.5.0
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.5.0>
npm notice Run `npm install -g npm#8.5.0` to update!
npm notice
npm ERR! code ERR_SOCKET_TIMEOUT
npm ERR! errno ERR_SOCKET_TIMEOUT
npm ERR! network Invalid response body while trying to fetch https://registry.npmjs.org/styled-jsx: Socket timeout
npm ERR! network This is a problem related to network connectivity.
npm ERR! network In most cases you are behind a proxy or have bad network settings.
npm ERR! network
npm ERR! network If you are behind a proxy, please make sure that the
npm ERR! network 'proxy' config is set properly. See: 'npm help config'
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2022-02-17T07_12_06_500Z-debug-0.log
The command '/bin/sh -c npm cache clear --force && npm install --legacy-peer-deps' returned a non-zero code: 1
docker file
FROM node:alpine
WORKDIR /app
ENV PORT 3000
COPY ./package.json /app/
COPY ./.npmrc ~
RUN npm cache clear --force && npm install --legacy-peer-deps
COPY . /app/
CMD ["npm", "start"]
as u can see I have added .npmrc file because I have read it somewhere but it didn't work or add npm cache clear --force so what should I do?
What version of Node your app is using? And what version of node you have installed on your OS?
You can check it using:
node -v
This image you used node:alpine is the newest version of the node, currently it's 17. So maybe you should use older one (the one you actualy have in your app).
You can find correct image on Docker Hub

Error "Your cache folder contains root-owned files, due to a bug in previous versions of npm" while "npx create-react-app example_app"

When I was trying to create a new react app using npx create-react-app example_app, I get this error
[Your cache folder contains root-owned files, due to a bug in previous
versions of npm which has since been addressed sudo chown -R 0:0
"/root/.npm"]
I even tried to re-install create-react-app again using npm i create-react-app, it is giving the same kind of
error.
I assume after searching about it that it is due to some permissions issue. My current user doesn't have permission to /home/shubham/.npm where shubham is my username, but I am not so sure about this.
I have tried to solve this error using chown command as
sudo chown -R <username>:<groupname> /home/shubham/.npm"
where <username> is Shubham and <groupame> is 1000, but it is still not working.
Request people to help me out.
If you need any more information, let me know.
This worked for me:
sudo npm cache clean --force
This is what helped me after going through the above answers. I hope it helps someone else too. After re-reading the npm error prompt, I adjusted the provided command to include the .npm path given in the error message. Below is a copy of my original error messages.
npm ERR! code EACCES
npm ERR! syscall access
npm ERR! path /home/vagrant/.npm-global/lib/node_modules
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 900:900 "/home/vagrant/.npm"
npm ERR! A complete log of this run can be found in:
npm ERR! /home/vagrant/.npm/_logs/2020-07-09T16_43_35_046Z-debug.log
[ExecStack] Exit code 243 Time 01:03
[error] Executing target-hook frontend-reqs failed.
[error] Command source:build:frontend-reqs exited with code 1.
Instead of using sudo chown -R 900:900 "/home/vagrant/.npm", I used sudo chown -R 900:900 "/home/vagrant/.npm-global". After that, I was able to use the previous command that caused the error with no issues.
Set the npm_config_cache environment variable
in linux
export npm_config_cache=/path/to/cache
in windows
set npm_config_cache=/path/to/cache
Try sudo chown -R 1000:1000 "/home/shubham/.npm"
I had to do both the root folder and the root/.npm
sudo chown -R 1001:1001 "/root"
sudo chown -R 1001:1001 "/root/.npm"
If you are using CI and share the CI slave with other teams, maybe not possible to sudo chown -R {group}:{user} "~/.npm" (i.e.: using Github Enterprise with Github Actions on shared runners
I add
# use local cache to work-around 'npm ERR! path ~/.npm/_locks/staging-xxx.lock' in GHA
cache=./npm-cache
into my .npmrc in the repo to solve the issue by using local npm cache dir
I had the same issue and several others while trying to update my npm packages. I will be honest I do not have enough knowledge of package handlers or why this fixed my situation, but I believe my version of npm and npx were causing the issues. I had errors immediately trying to install npx, node and create-react-app with my old and out of date version of npm.
I could not run npm install npx -g without --force. Once I did that I also ran npm install npm -g --force. After this I could already tell things were different.
After npm and npx were completely overwritten, I ran npm install node -g and npm install create-react-app -g without any weird problems. I created a new react app and started it error free.
(I also ran the cache command before all of this. sudo npm cache clean --force which I am unsure if it helped).
I was getting this while running npx #11ty/eleventy as root:
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 1000:1000 "/root/.npm"
No, /root/.npm is supposed to be owned by root. It's not at all due to a bug in a previous version of npm. And yes, the root user has permission to read and write that directory. So this is a bug in the current version of npm that prevents building the project as root.
Of course following the nonsensical instructions to change the root homedir's ownership does not work.
In my case, I was running it as root as part of a build script that needs root for an rsync to complete:
#!/bin/bash -eu
# mybuildscript
npx #11ty/eleventy
rsync _site/ /srv/www/ # This needs to be run as root
So my workaround was to run that single line as an unprivileged user using sudo:
#!/bin/bash -eu
# mybuildscript
sudo -u ki9 npx #11ty/eleventy
rsync _site/ /srv/www/ # This needs to be run as root
I am using npm version 7.5.2. Hopefully this will be addressed in a future version of npm.
I also tried all of the above steps on my MAC Catalina, but didn't resolve my issue. These steps resolved my problem:
npm update
npx --ignore-existing create-react-app my-app
Thanks to this comment
This will work:
sudo chown -R 1000:1000 "~/.npm"
Neither force-cleaning the cache nor using chown worked for me, but deleting the folder did work and fixed the issue.
My error was:
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 501:20 "/Users/aw/.npm"
The fix was to permanently erase the .npm folder in question, which I did using rm -rf:
sudo rm -rf /Users/aw/.npm
(Mandatory warning: this is a dangerous command if you typo it.)
I encountered the same issue and the problem with mine was that I was running an older version of npm. After updating npm and removing the .npmrc file, it worked just fine.
npm install -g npm#latest
rm .npmrc
Be careful before deleting the .npmrc file, take a backup as it will reset your npm configuration.
I fixed mine by running:
sudo npm cache clean --force
followed by removing the root owned files.
first, to view the file owners and group:
cd /Users/username/
ls -la
You have to check the owner of .npm, changed to non-root user:
sudo chown -R username:group "/Users/username/.npm"
or for global .npm-global
sudo chown -R username:group "/Users/username/.npm-global"
replace keyword: username/group accordingly
It helped me:
Remove and install npm again
It work for me now!
What I did? (I'm not saying it's the best way to fix this but i'ts working for me. I'm still looking for the best explications for this issue)
sudo rm -Rf /home/[YOUR_USER_NAME]/.npm-global/lib/node_modules/
and run your command again.
My explication is that it seems like something is corrupted in the node_modules's folder.
As it's not risky to delete it I did it and it works now.
Try sudo npx create-react-app example_app or in my case sudo npm install #vue/cli
I tried everything else here, but in the end realised that it might just be the command that I was running was not able to escalate the correct permissions.
Find error in your log file:
verbose Error: EACCES: permission denied, mkdir '/Users/xxx/.tnpm_tmp/npm-52731-e91f6671'
Use that error in your condition.
sudo chown -R 502:20 "/Users/XXX/.tnpm_tmp"
I solve the problem with the following commands
Install dependence > npm install create-react-app
run > create-react-app project_name
happy hack!!
Try to create your react app using yarn package manager.

How do I fix the npm install on Linux?

I'm trying to use npm install to install a package but I keep getting below error.
I tried updating and downloading again from root but nothing seems to work.
hackathonday1-2 git:(save-button) ✗ npm install file-saver --save
npm WARN checkPermissions Missing write access to
/home/salman/node_modules/axios npm WARN checkPermissions Missing
write access to /home/salman/node_modules/coffeescript npm WARN
checkPermissions Missing write access to
/home/salman/node_modules/coffee-script npm WARN checkPermissions
Missing write access to /home/salman/node_modules/file-saver npm WARN
checkPermissions Missing write access to
/home/salman/node_modules/materialize-css npm WARN enoent ENOENT: no
such file or directory, open '/home/salman/package.json' npm WARN
salman No description npm WARN salman No repository field. npm WARN
salman No README data npm WARN salman No license field.
npm ERR! code EACCES npm ERR! syscall access npm ERR! path
/home/salman/node_modules/axios npm ERR! errno -13 npm ERR! Error:
EACCES: permission denied, access '/home/salman/node_modules/axios'
npm ERR! [Error: EACCES: permission denied, access
'/home/salman/node_modules/axios'] { npm ERR! stack: "Error: EACCES:
permission denied, access '/home/salman/node_modules/axios'", npm ERR!
errno: -13, npm ERR! code: 'EACCES', npm ERR! syscall: 'access',
npm ERR! path: '/home/salman/node_modules/axios' npm ERR! } npm ERR!
npm ERR! The operation was rejected by your operating system. npm ERR!
It is likely you do not have the permissions to access this file as
the current user npm ERR! npm ERR! If you believe this might be a
permissions issue, please double-check the npm ERR! permissions of the
file and its containing directories, or try running npm ERR! the
command again as root/Administrator.
npm ERR! A complete log of this run can be found in: npm ERR!
/home/salman/.npm/_logs/2019-09-24T03_37_30_909Z-debug.log
If there is a permission error on Linux for npm install, you can try to include sudo at the beginning of command. sudo npm install. Also make sure node.js is installed globally on your machine. Also make sure you have a package.json folder.
It's simply complaining about the fact that you don't own the folders /home/salman/node_modules/axios, /home/salman/node_modules/file-saver etc. Since it is your home directory, there really shouldn't be any directory or files that you don't own in /home/salman. My guess is that this happened because you ran npm with sudo causing it to create some files in your home folder that is owned by root instead of salman.
To fix the permission issue simply retake ownership of the node_modules folder:
cd /home/salman
sudo chown -R salman:salman node_modules
The -R flag makes chown recursively set you as the owner to all files and subfolders in the directory.
Side note: you really shouldn't use your home directory as your npm project directory. Do npm install in individual project directories. Yes, this wastes disk space but disk space is cheap and can freely be wasted. Even if you have 10 node.js projects you are unlikely to use more than 5GB of disk space even though there are lots of duplicate code files. A single HD movie is sometimes larger than that. Typical disk space usage for code is around 2GB.
sudo chown -R $USER /home/salman/node_modules
This command is useful.. Run it on your system..

create-react-app newproject commandline is not working for me

for some reason ive been ending up with "command not found" when i type in the create-react-app newproject command. Its been giving me this error:
npm WARN checkPermissions Missing write access to /Users/kennyquach/.npm-global/lib/node_modules/create-react-app
npm ERR! path /Users/kennyquach/.npm-global/lib/node_modules/create-react-app
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/Users/kennyquach/.npm-global/lib/node_modules/create-react-app'
npm ERR! { Error: EACCES: permission denied, access '/Users/kennyquach/.npm-global/lib/node_modules/create-react-app'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/Users/kennyquach/.npm-global/lib/node_modules/create-react-app\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/Users/kennyquach/.npm-global/lib/node_modules/create-react-app' }
npm ERR!
npm ERR! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR!
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/kennyquach/.npm/_logs/2018-11-28T17_50_32_739Z-debug.log
any help is appreciated! Thanks!
As the error clearly shows you dont have write access to /Users/kennyquach/.npm-global/lib/node_modules/create-react-app
try changing access to 777 for all of .npm-global folders and then give a try.
You are high likely using Mac OS as Operating System. This is a general issue of globally installed packages in MacOS that caused by built-in node application's file permissions. Actually you can get over this by executing create-react-app as root, but i don't recommend that, it's not useful and it's risky.
So you got 2 options. (First one is hard to do, second is blazing fast)
1-) Completely remove Node from your System and install it with Brew. You can easily update node with that package manager and install any other popular developer tools too (Like: mongodb, mysql, pgsql, rabbitmq etc.).
You can get brew from here: https://brew.sh and install node with that code: brew install node
2-) You can easily give read, write, execute access to your folders and files. You can do it like this: sudo chmod -R 777 /Users/kennyquach/.npm-global/ when sudo asks your password, use your Administrator password.
This looks like an access issue. I faced same issue in MAC OS X, when I tried running the command with sudo, it worked for me.
sudo npm install -g create-react-app

npm install / bower install issue and deprecated modules with angular-phonecat setup

I am trying to run npm install on my terminal as part of the setup for angular-phonecat as per the instructions on https://docs.angularjs.org/tutorial
When I run the command I am getting issues with deprecated modules and errors when reaching the bower install section.
Does anybody know how I can update the deprecated modules to avoid the warnings and how I can fix the bower errors?
Here is the output I am receiving:
npm WARN deprecated tough-cookie#2.2.2: ReDoS vulnerability parsing Set-Cookie https://nodesecurity.io/advisories/130
npm WARN deprecated minimatch#0.3.0: Please update to minimatch 3.0.2 or higher to avoid a RegExp DoS issue
-
> fsevents#1.0.14 install /Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/karma/node_modules/chokidar/node_modules/fsevents
> node-pre-gyp install --fallback-to-build
[fsevents] Success: "/Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/karma/node_modules/chokidar/node_modules/fsevents/lib/binding/Release/node-v46-darwin-x64/fse.node" already installed
Pass --update-binary to reinstall or --build-from-source to recompile
> angular-phonecat#0.0.0 postinstall /Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat
> bower install
bower EACCES EACCES: permission denied, unlink '/Users/Eamon/.cache/bower/registry/bower.herokuapp.com/lookup/jquery_d223e'
Stack trace:
Error: EACCES: permission denied, unlink '/Users/Eamon/.cache/bower/registry/bower.herokuapp.com/lookup/jquery_d223e'
at Error (native)
Console trace:
Error
at StandardRenderer.error (/Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/bower/lib/renderers/StandardRenderer.js:81:37)
at Logger.<anonymous> (/Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/bower/lib/bin/bower.js:110:26)
at emitOne (events.js:77:13)
at Logger.emit (events.js:169:7)
at Logger.emit (/Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/bower/lib/node_modules/bower-logger/lib/Logger.js:29:39)
at /Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/bower/lib/commands/index.js:48:20
at _rejected (/Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/bower/lib/node_modules/q/q.js:844:24)
at /Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/bower/lib/node_modules/q/q.js:870:30
at Promise.when (/Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/bower/lib/node_modules/q/q.js:1122:31)
at Promise.promise.promiseDispatch (/Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/node_modules/bower/lib/node_modules/q/q.js:788:41)
System info:
Bower version: 1.7.9
Node version: 4.4.0
OS: Darwin 15.6.0 x64
npm ERR! Darwin 15.6.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
npm ERR! node v4.4.0
npm ERR! npm v2.14.20
npm ERR! code ELIFECYCLE
npm ERR! angular-phonecat#0.0.0 postinstall: `bower install`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the angular-phonecat#0.0.0 postinstall script 'bower install'.
npm ERR! This is most likely a problem with the angular-phonecat package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR! bower install
npm ERR! You can get information on how to open an issue for this project with:
npm ERR! npm bugs angular-phonecat
npm ERR! Or if that isn't available, you can get their info via:
npm ERR!
npm ERR! npm owner ls angular-phonecat
npm ERR! There is likely additional logging output above.
npm ERR! Please include the following file with any support request:
npm ERR! /Users/Eamon/Documents/Scripting/Web Development/Learning/Javascript/Angularjs/angular-phonecat/npm-debug.log
I have tried searching on other posts with similar issues but none of these have helped me find a solution:
error when npm install
Got an error while running "npm install" on angular-phonecat directory
Cannot npm install for angular-phonecat tutorial : Cannot find module 'update-notifier'
I have also tried running sudo npm install with the same issue. I have a feeling the bower install issues are due to the setup of the bower cache looking at the error output but I am not 100% certain.
Has anyone encountered similar issues when setting up the installation for angular-phonecat?
Any help would be greatly welcomed.
Many Thanks,
Eamon
ISSUE: You (the user) don't have the right set of permissions for the directory.
The instant way out is to run the npm install using sudo, but this may give you the same error, or improper installation.
AND changing directory ownership is not a good option, a temporary patch. I am answering the question, as I feel I have a more elegant solution/suggestion to the problem. I came across same issues multiple times i.e. 'npm install -g #angular/cli'.
Uninstalled the package and executed the following commands (in the order mentioned) to have clean installation.
Solution/Suggestion: Change npm's Default Directory (from official docs)
Back-up your computer before moving forward.
(optional) In case you have a erroneous installation, first uninstall it:
npm uninstall <package-name> # use sudo if you used it while installation
npm cache verify # or, npm cache clean for npm version below 5.x.x
Make a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
Open or create a ~/.profile or ~/.bash_profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
Back on the command line, update your system variables, or restart the terminal:
source ~/.profile
(optional) Test: Download a package globally without using sudo.
npm install -g jshint
Having looked into this it appears that bower was having issues with permissions and was resolved by running the bower install separately using sudo:
sudo bower install --allow-root
However, you should not use sudo with bower. It is likely that if you have to then the ~/.cache has been set incorrectly either by installing using sudo or installing your first package via sudo. More info about this can be found here: http://www.competa.com/blog/2014/12/how-to-run-npm-without-sudo/
Instead you should rectify the ownership by running the following:
sudo chown -R $user ~/.npm
sudo chown -R $user ~/.config
To find your user you can simply run the following command on the command line:
$ whoami
If you want to open to a wider group you can also add a group to the chown command. To find out which group your user belongs to you can type the following command:
$ groups
To set the group at the same time as the user simply change the command to the following and replace $user and $group with your desired user and group:
sudo chown -R $user:$group ~/.npm
sudo chown -R $user:$group ~/.config
If you are seeing an issue like one of the below when running a bower install during your npm install:
EACCES: permission denied, open '/some/directory'
EACCES: permission denied, unlink '/some/directory'
You will need to change the permissions to the folder containing the file to be your user by doing:
sudo chown -R USER /some/directory
Just change the folder that the file is stored in, not the file itself. When you run npm install after this it will work if it needs to install any bower components that are having issues installing while using your current user and not using sudo.
Thanks,
Eamon

Categories

Resources