npm ERR! code EACCESS by installing #angular/cli - node.js

Environment:
Ubuntu 16.04
node v8.11.1 (installed with package manager)
npm v5.6.0
After the clean installation of npm and trying to install #angular/cli
npm install -g #angular/cli
I'm getting an error related with EACCESS that it is probably related with permissions because it disappears with root access. The thing is that it is not recommended to use it that way, so how could I solve this?
Console ERROR
$ npm install -g #angular/cli
npm WARN checkPermissions Missing write access to /usr/lib/node_modules
npm ERR! path /usr/lib/node_modules
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access
npm ERR! Error: EACCES: permission denied, access '/usr/lib/node_modules'
npm ERR! { Error: EACCES: permission denied, access '/usr/lib/node_modules'
npm ERR! stack: 'Error: EACCES: permission denied, access \'/usr/lib/node_modules\'',
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'access',
npm ERR! path: '/usr/lib/node_modules' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/user/.npm/_logs/2018-04-25T15_23_36_781Z-debug.log
File .npm/_logs/2018-04-25T15_23_36_781Z-debug.log
2566 warn checkPermissions Missing write access to /usr/lib/node_modules
2567 verbose stack Error: EACCES: permission denied, access '/usr/lib/node_modules'
2568 verbose cwd /opt/workspace/roscam-front
2569 verbose Linux 2.6.32-042stab120.19
2570 verbose argv "/usr/bin/node" "/usr/bin/npm" "install" "-g" "#angular/cli"
2571 verbose node v8.11.1
2572 verbose npm v5.6.0
2573 error path /usr/lib/node_modules
2574 error code EACCES
2575 error errno -13
2576 error syscall access
2577 error Error: EACCES: permission denied, access '/usr/lib/node_modules'
2577 error { Error: EACCES: permission denied, access '/usr/lib/node_modules'
2577 error stack: 'Error: EACCES: permission denied, access \'/usr/lib/node_modules\'',
2577 error errno: -13,
2577 error code: 'EACCES',
2577 error syscall: 'access',
2577 error path: '/usr/lib/node_modules' }
2578 error Please try running this command again as root/Administrator.
2579 verbose exit [ -13, true ]

One option to deal with this problem will be to change npm's default directory to use a different directory.
We need to make a directory for global installations, in this example inside user directory:
mkdir ~/.npm-global
We configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
Open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
We update your system variables:
source ~/.profile
Now we can test by installing a package globally without using root permissions.
npm install -g jsonfile
Another option to avoid all these steps and modifying ~/.profile, it will be by defining an ENV variable with the following command(:
NPM_CONFIG_PREFIX=~/.npm-global
npm reference

I had the EACCES permission error too. I did a fresh install of Ubuntu 18.04. The 16.04 version may not be much different. It all works for me. Hope this helps.
----------- FOR YOU, YOU SHOULD APPLY THIS CODE FROM HERE
sudo apt-get install curl software-properties-common
curl -sL https://deb.nodesource.com/setup_10.x | sudo -E bash -
sudo apt install nodejs
node -v
npm -v
npm init
whoami
which npm # returned /usr/bin
npm config get prefix # returned /usr
npm config set prefix /usr/bin
npm config get prefix
ls -la /usr/bin/npm # has a symbolic link to ../lib/node_modules/npm/bin/npm-cli.js
sudo chown -R your_user /usr/bin/npm # NOT /usr/bin or we lock out sudo too!!!!
sudo chown -R your_user app-folder/
ls -la /usr/bin/npm
npm init # I was curious to see if this still works
npm install # WORKS GREAT!!! No need for sudo now.:)
----------- TO THERE
THIS IS THE USE CASE I WORKED ON AFTER I INSTALLED THE ABOVE. YOURS SHALL WORK TOO IF THE ABOVE IS WELL SET UP.
npm start # script
npm run start:prod # works as well
npm i debug --save-dev # works but need to install 'make'
sudo apt install build-essential
npm i debug --save-dev # installed and launched successfully!
Note: if you were to install
npm i debug --global instead,
you may still get that EACCES permission error as your local user will not be able to access root permissions elsewhere in your file system. That's why we use 'change ownership' (i.e. chown your_user: see above in the code).

Related

When I try to install nodemon i get this error message

npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/lib/node_modules/nodemon
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir'/usr/local/lib/node_modules/nodemon'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/nodemon'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/lib/node_modules/nodemon'
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:
Looks like the problem is with the package generator-karma, not sure if this is the problem or not.
Can anyone show me what i need to do to get this installing correctly.
Thanks
Sanil
I believe you're trying to install a global package on your system by using npm install -g nodemon, then got permission denied, which is shown in error message.
You can't install a global package without root permission. If you want to do so, just execute it with root permission, like using sudo: sudo npm i -g nodemon or switch to root then execute again.
This looks like a permissions issue in your home directory. To reclaim ownership of the node_modules directory execute:
sudo chown -R $(whoami) ~/node_modules
Node.js error EACCES means you don't have access to the path it's specifying. In this case, /usr/local/lib/... is owned by the root user. See the command output here:
$ ls -l /usr/local/lib
total 12
drwxr-xr-x 4 root root 4096 Apr 7 23:45 node_modules
Nobody but root is allowed to write to the node_modules folder. This can be solved by prefixing your npm command with sudo to run the command as root.
See other: Understanding Linux File Permissions - Linuxize

Install ReactJS on Ubuntu 18.04 -- npm permission denied

I am new to Linux and I am trying to get set-up with nodejs, but I have not been able to figure out why I can't install react. I am following directions that I have seen on the web, but I am wondering why I seem to not have the privileges necessary to install react. It's a personal environment, so I wasn't expecting any issue. Below is what I have run and the final error that the last line gave me.
sudo apt update && sudo apt upgrade
sudo apt install nodejs
sudo npm install npm
node -v
v8.10.0
npm -v
3.5.2
sudo npm install npm#latest -g
npm -v
6.10.0
npm install -g create-react-app
Everything above runs just fine until the last command. Then I get the following error, regardless of working directory.
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' }
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! /home/me/.npm/_logs/2019-07-06T19_33_32_971Z-debug.log
Using npx (with npm 5.2+)
If you're using npm 5.2+, you may create a ReactJS app like below:
npx create-react-app my-app
Now your app is in a folder my-app, you can cd into the folder and run npm start.
Using older versions of npm with npm install
You may also install it with a global install with npm, infact for older npm versions (< 5.2) the official documentation for create-react-app links to instructions by Dan Abramov (#co-author of create-react-app):
npm install -g create-react-app
However you may need sudo for a global -g install or work around it
Everything above runs just fine until the last command. Then I get the following error, regardless of working directory.
That's because your last command is a global install (-g).
Unless there is a reason against, you may install it with sudo:
sudo npm install -g create-react-app
To install without sudo, please refer to this question: npm throws error without sudo
I was also having this issue, here is how it was resolved
Make sure you have npm installed or use:
sudo apt install npm
Then
sudo npm -g install create-react-app
To create the app I did not use 'npm' before the command line, instead use this:
create-react-app nameofyourapp
That worked for me.

Angular CLI cannot install errno -13

could anyone advise what I should do please?
My node and npm version as follows:
$ viviantekiMacBook-Air-2:~ Vivi1an$ node -v
v8.11.1
$ viviantekiMacBook-Air-2:~ Vivi1an$ npm -v
5.6.0
I tried to install Angular CLI by following the instructions on their website but I got an error after I typed in npm install -g #angular/cli
Error info as below:
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' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/Vivi1an/.npm/_logs/2018-04-02T09_00_20_531Z-debug.log
viviantekiMacBook-Air-2:~ Vivi1an$
I have downloaded node.js in a local folder to use Babel, not sure if this has anything to do with it?
Many thanks!
sudo npm install -g #angular/cli
i have the same problem I give way perhaps work with you
This is how to solve it. Run this command:
sudo chown -R $USER /usr/local/lib/node_modules
sudo means we are running this command as root, the system super user. This is because we don’t have permission to write to that folder, but root will be able to fix any permission. This command also means the system will ask for your password to confirm.
chown is the command we use to change the owner of a file or folder. We set the -R option to change the owner recursively, so we also get owner access to all the files already contained in there.
$USER is an environment variable automatically set to your username.
And the final piece is the folder path.
Running this path will make the folder yours, so you can safely run your npm install -g commands!
i go with the previous answer i put it and i install angular well,
but i appear for me another maybe also related with
npm audit
for resolve, it follows this question link answer
how to fix the npm audit report
i hope is a benefit for you

Including module installation arguments in package.json

I am using the node serialport library, which needs to be installed using the --unsafe-perm and --build-from-source arguments. I only wants those arguments to be used when installing serialport. If I run the following on the command line it works fine:
sudo npm install serialport#5.0.0 --unsafe-perm --build-from-source
Based on this post, my understanding is that you accomplish that by using the preinstall script, like so:
"preinstall": "sudo npm install serialport#5.0.0 --unsafe-perm --build-from-source"
However, I'm getting the following error when I run that:
npm ERR! Error: EACCES: permission denied, mkdir '/Users/test/node_modules/.staging'
npm ERR! at Error (native)
npm ERR! { Error: EACCES: permission denied, mkdir '/Users/test/node_modules/.staging'
npm ERR! at Error (native)
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/Users/test/node_modules/.staging' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
So it's not running as root event though I have sudo specified in the command?
How do I get serialport installed through package.json with those flags?
Okay, this took a while to figure out, but I think I get it now.
It turns out that when you have a package.json file that contains a preinstall or postinstall script that you are executing as root, npm will run this with reduced permissions. You have to include the --unsafe-perms flag to let it execute the script as root. So the long and short is that you need to run
sudo npm i --unsafe-perm
or you can create a .npmrc file with this entry:
unsafe-perm = true
If you go the .npmrc route you don't have to specify --unsafe-perm on the command line.
Of course, all of this is only necessary when you are running npm i as root, which isn't really safe. So if you create a regular user and give them full access to the directly in which you are installing your packages, you don't have to worry about --unsafe-perm.
As for --build-from-source, you don't have to worry about that either because when electron-rebuild realizes that it can't download the appropriate package for your environment, it will build it for you.

Error: EACCES: permission denied when running `npm install` on Elastic Beanstalk

I've provisioned a default clean node.js app via Elastic Beanstalk, and have a node.js script trying to run npm install inside the project directory (/var/app/current/deploy-dist), however, the following permission error is thrown:
npm WARN locking Error: EACCES: permission denied, open '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock'
npm WARN locking at Error (native)
npm WARN locking /tmp/.npm/_locks/staging-f212e8d64a01707f.lock failed { Error: EACCES: permission denied, open '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock'
npm WARN locking at Error (native)
npm WARN locking errno: -13,
npm WARN locking code: 'EACCES',
npm WARN locking syscall: 'open',
npm WARN locking path: '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock' }
npm WARN deploy-dist No description
npm WARN deploy-dist No repository field.
npm WARN deploy-dist No license field.
npm ERR! Linux 4.4.35-33.55.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v6.9.1-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v6.9.1-linux-x64/bin/npm" "install"
npm ERR! node v6.9.1
npm ERR! npm v3.10.8
npm ERR! path /tmp/.npm/_locks/staging-f212e8d64a01707f.lock
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open
npm ERR! Error: EACCES: permission denied, open '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock'
npm ERR! at Error (native)
npm ERR! { Error: EACCES: permission denied, open '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock'
npm ERR! at Error (native)
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'open',
npm ERR! path: '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.
npm ERR! Please include the following file with any support request:
npm ERR! /var/app/current/deploy-dist/npm-debug.log
The package.json is just a:
{
"dependencies": {
"node-fetch": "^1.3.3"
}
}
Running npm install with sudo obviously works, but is preferred to be avoided as a solution.
Setting NPM_CONFIG_PREFIX to a directory at ~ as per npm docs suggestion didn't work either, and the problem persists.
I suspect the problem lies in incorrect permissions for /tmp/.npm, which are
drwxr-xr-x 114 root root 4.0K Dec 27 17:04 .npm
This is confusing, as I expected a simple npm install to work out of the box.
UPDATE: Should not that the project directory already contains a node_modules folder, but even removing it and running npm install doesn't fix it.
I had this problem! You can use ebextensions to create a post-deploy script that changes the permissions of the tmp/npm/.locks folder.
In your node.js project, create a .ebextensions folder if you haven't got one already. Then, add a new config file, e.g. 00_create_postdeploy_script.config, with the following yaml:
files:
"/opt/elasticbeanstalk/hooks/appdeploy/post/99_fix_node_permissions.sh":
mode: "000755"
owner: root
group: root
content: |
#!/usr/bin/env bash
chown -R nodejs:nodejs /tmp/.npm/_locks/
When you deploy, this will create a script in /opt/elasticbeanstalk/hooks/appdeploy/post called 99_fix_node_permissions.sh, which looks like this:
#!/usr/bin/env bash
chown -R nodejs:nodejs /tmp/.npm/_locks/
Because it's in that post folder, it will be run automatically after your app has deployed -- and hence change the permissions as required.
EDIT: If you're having trouble with the permissions of the whole .npm folder, then you should change the last line of the config file to:
chown -R nodejs:nodejs /tmp/.npm/
I have had this problem in past and in my case cleaning the cache fixed my issue.
Please try this
npm cache clean
Hope it helps.
The following command will fix the issue. it worked for me.
sudo chown -R 1000:1000 "/home/user/.npm"

Resources