问题
I run npm install lodash but it throws Error: EACCES: permission denied error. I know it is permission issue but as far as I know, sudo permission is not required for installing node module locally. If I run it with sudo, it gets installed inside ~/node_modules folder. drwxrwxr-x is the file permission of existing folder. I can't figure out what might have gone wrong.
Below is the error message.
npm ERR! tar.unpack untar error /home/rupesh/.npm/lodash/4.13.1/package.tgz
npm ERR! Linux 3.13.0-88-generic
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "lodash"
npm ERR! node v4.3.1
npm ERR! npm v2.14.12
npm ERR! path /home/rupesh/node_modules/lodash
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir
npm ERR! Error: EACCES: permission denied, mkdir '/home/rupesh/node_modules/lodash'
npm ERR! at Error (native)
npm ERR! { [Error: EACCES: permission denied, mkdir '/home/rupesh/node_modules/lodash']
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/home/rupesh/node_modules/lodash',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/home/rupesh/node_modules/lodash',
npm ERR! fstream_class: 'DirWriter',
npm ERR! fstream_stack:
npm ERR! [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:35:25',
npm ERR! '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:47:53',
npm ERR! 'FSReqWrap.oncomplete (fs.js:82:15)' ] }
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! /home/rupesh/Desktop/es6/npm-debug.log
回答1:
This command fix the issue. It worked for me:
sudo npm install -g --unsafe-perm=true --allow-root
回答2:
I have same issue with webpack server installation on globally, Use steps from this Url Solved my issue, my be work for you.
Steps mention above There: Back-up your computer before you start.
Make a directory for global installations:
1.
mkdir ~/.npm-globalConfigure npm to use the new directory path:
2.
npm config set prefix '~/.npm-global'Open or create a ~/.profile file and add this line:
3.
export PATH=~/.npm-global/bin:$PATHBack on the command line, update your system variables:
4.
source ~/.profile
Test: Download a package globally without using sudo.
npm install -g jshint
Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don't want to modify ~/.profile):
NPM_CONFIG_PREFIX=~/.npm-global
回答3:
I had problem on Linux. I wrote
chown -R myUserName ./*
in my project folder.
回答4:
Creating package.json using npm init solved my issue.
回答5:
From what i can see in your logs you posted:
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/home/rupesh/node_modules/lodash',
npm ERR! fstream_type: 'Directory',
npm ERR! fstream_path: '/home/rupesh/node_modules/lodash',
npm ERR! fstream_class: 'DirWriter',
directory /home/rupesh/node_modules/ doesn't have necessary permissions to create directory so run chown -r rupesh:rupesh /home/rupesh/node_modules/ this should solve it.
回答6:
FWIW I had the same symptoms, but with a different package. Creating package.json and running npm init did NOT solve my issue.
On this system, apparently new folders in this location were being created with root permissions. During npm install, new folders are created. This caused npm install to fail partway, even with sudo.
The solution was to run npm install app in a different location with no root umask.
回答7:
It doesn't have write permissions for others (r-x). Try with
chmod a+w <folder>
and repeat.
回答8:
First install without -g (global) on root. After try using -g (global) It worked for me.
回答9:
This solved my issue straight away - mac Mojave 10.14.6 - PhpStorm.
Unhandled rejection Error: EACCES: permission denied, mkdir '/Users/myname/.npm/_cacache/index-v5/fb/5a'
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
Original post: https://stackoverflow.com/a/50639828
回答10:
I solved this issue by changing the permission of my npm directory. I went to the npm global directory for me it was at
/home/<user-name>
I went to this directory by entering this command
cd /home/<user-name>
and then changed the permission of .npm folder by entering this command.
sudo chmod -R 777 ".npm"
It worked like a charm to me. But there is a security flaw with this i.e your global packages directory is accessible to all the levels.
回答11:
Remove dist folder and this solve my problem!!
回答12:
Execute these commands and issue will be solved!
sudo chmod -R 777 /usr/local/bin
sudo chmod -R 777 /usr/local/lib/node_modules
回答13:
Try to give all permission to your project folder with below command
sudo chmod -R 777 /yourProjectDirectoryName
run with
sudo npm install lodash
回答14:
Here's the solution for GNU/Linux (Debian) users (Replace USERNAME with your username):
sudo chown -R $USER:$(id -gn $USER) /home/USERNAME/.config
回答15:
LUBUNTU 19.10 / Same issue running: $ npm start
dump: Error: EACCES: permission denied, open '/home/simon/xxx/pagebuilder/resources/scripts/registration/node_modules/.cache/@babel/register/.babel.7.4.0.development.json' at Object.fs.openSync (fs.js:646:18) at Object.fs.writeFileSync (fs.js:1299:33) at save (/home/simon/xxx/pagebuilder/resources/scripts/registration/node_modules/@babel/register/lib/cache.js:52:15) at _combinedTickCallback (internal/process/next_tick.js:132:7) at process._tickCallback (internal/process/next_tick.js:181:9) at Function.Module.runMain (module.js:696:11) at Object. (/home/simon/xxxx/pagebuilder/resources/scripts/registration/node_modules/@babel/node/lib/_babel-node.js:234:23) at Module._compile (module.js:653:30) at Object.Module._extensions..js (module.js:664:10) at Module.load (module.js:566:32)
Looks like my default user (administrator) didn't have rights on node-module directories.
This fixed it for me!
$ sudo chmod a+w node_modules -R ## from project root
来源:https://stackoverflow.com/questions/38323880/error-eacces-permission-denied