可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
I have managed to corrupt my npm
install, and whenever I try to install packages using npm install
, I receive error messages along these lines:
Unhandled rejection Error: EACCES: permission denied, open '/Users/marknorgate/.npm/_cacache/tmp/a449402d'
I have tried reinstalling node & npm, and I have also tried to relocate my npm cache elsewhere using these instructions but nothing works.
How can I get it working?
回答1:
Restore ownership of the user's npm related folders, to the current user, like this:
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
回答2:
sudo chown -R $(whoami) ~/.npm
sudo chown -R $(whoami) ~/.config
回答3:
This happens if the first time you run NPM it's with sudo, for example when trying to do an npm install -g.
The cache folders need to be owned by the current user, not root.
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
This will give ownership to the above folders when running with normal user permissions (not as sudo).
It's also worth noting that you shouldn't be installing global packages using SUDO. If you do run into issues with permissions, it's worth changing your global directory. The docs recommend:
mkdir ~/.npm-global
npm config set prefix '~/.npm-global'
Then updating your PATH in wherever you define that (~/.profile etc.)
export PATH=~/.npm-global/bin:$PATH
You'll then need to make sure the PATH env variable is set (restarting terminal or using the source command)
https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
回答4:
sudo npm cache clean --force --unsafe-perm
and then npm i goes normally
回答5:
Above answer didn't work for me. Just try to run your command with --unsafe-perm
.
e.g
npm install -g node@latest --unsafe-perm
This seems to solve the problem.
回答6:
If none of suggestions in answers worked out, try the following command: npm cache clear --force
. It worked for me.
I found it at https://github.com/vuejs/vue-cli/issues/1809.
回答7:
just create folders _cache/tmp
under .npm
manually at location /Users/marknorgate/.npm/_cacache/tmp
and run your command with administrator access
回答8:
sudo npm install --unsafe-perm=true --allow-root
This was the one that worked for me
回答9:
This worked for me!
Resolving EACCES permissions errors when installing packages globally
回答10:
Simply do sudo npm cache clean --force --unsafe-perm
and npm i
will go normally.
回答11:
change ownership
sudo chown -R $USER:$GROUP ~/.npm
sudo chown -R $USER:$GROUP ~/.config
worked for as i installed package using sudo
回答12:
Try using this:
On the command line, in your home directory, create a directory for global installations:
mkdir ~/.npm-global
Configure npm to use the new directory path:
npm config set prefix '~/.npm-global'
In your preferred text editor, open or create a ~/.profile file and add this line:
export PATH=~/.npm-global/bin:$PATH
On the command line, update your system variables:
source ~/.profile
Now use npm install it should work.
回答13:
you can try following command for expo :
sudo chown -R $USER:$GROUP ~/.expo
回答14:
as per npm community
sudo npm cache clean --force --unsafe-perm
and then npm install goes normally.
source: npm community-unhandled-rejection-error-eacces-permission-denied