Javascript npm WARN checkPermissions 缺少对 /usr/local/lib/node_modules 的写访问权限

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/52979927/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 05:02:06  来源:igfitidea点击:

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

javascriptreactjsmacosnpmmonaca

提问by Shivam ashtikar

I am trying to install monaca with this command.

我正在尝试使用此命令安装 monaca。

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' }

npm WARN checkPermissions 缺少对 /usr/local/lib/node_modules 的写访问权限 npm ERR!路径 /usr/local/lib/node_modules npm ERR!代码 EACCES npm ERR!错误号 -13 npm 错误号!系统调用访问 npm ERR!错误:EACCES:权限被拒绝,访问'/usr/local/lib/node_modules' npm ERR!{ 错误:EACCES:权限被拒绝,访问'/usr/local/lib/node_modules' npm ERR!堆栈:'错误:EACCES:权限被拒绝,访问\'/usr/local/lib/node_modules\'',npm ERR!错误号:-13,npm 错误!代码:'EACCES',npm 错误!系统调用:'访问',npm 错误!路径:'/usr/local/lib/node_modules' }

Any idea how to solve this problem? Thank you

知道如何解决这个问题吗?谢谢

采纳答案by Snickers

An inadvisable way to fix the issue would be to use sudo:

解决此问题的一种不可取的方法是使用 sudo:

sudo npm install -g monaca

However it would be better to find a way around this without using sudo.

但是,最好在不使用 sudo 的情况下找到解决此问题的方法。

npm install -g less does not work

npm install -g less 不起作用

回答by Shivam ashtikar

add following lines to ~/.bashrc after installing npm:

安装 npm 后,在 ~/.bashrc 中添加以下几行:

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

正如@contemplator 所提到的,避免使用 sudo

回答by contemplator

Note: It is highly recommended to avoid using sudowith npm!

注意:强烈建议避免sudo与 npm 一起使用!

Using sudo is not recommended. It may give you permission issue later. While the above works, use these instructionsto fix your issue permanently.

不建议使用 sudo。它可能会在以后给你权限问题。虽然上述方法有效,但请使用这些说明永久解决您的问题。

回答by Ebrahim

Well, I used --save-devand installed it not globally or using -g, the main problem occurs while you want it to write on default node_modulesfolder.

好吧,我--save-dev没有全局使用和安装它,也没有使用-g,主要问题发生在您希望它写入默认node_modules文件夹时。

It solved my problem after 4 hours of checking multiple issues.

在检查多个问题 4 小时后,它解决了我的问题。

I even suggest you to use the npm initand make a package.jsonfor a better dependency checking and then run npminstall afterward. this video helps you for this https://www.youtube.com/watch?v=rTsz09zRuTU

我什至建议你使用npm init并制作package.json一个更好的依赖性检查,然后run npm安装。此视频可帮助您解决此问题https://www.youtube.com/watch?v=rTsz09zRuTU