是什么原因导致错误:EACCES:权限被拒绝,访问'/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!   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/macbookmd101/.npm/_logs/2018-02-21T16_26_08_421Z-debug.log

当前回答

我得到了同样的错误,并解决它使用命令

Sudo NPM install -g expo-cli——unsafe-perm

在运行命令后的图像中

然后执行以下命令更新NPM

NPM install -g npm@latest

我很容易就解决了这个问题。

其他回答

只要在npm命令前加上“sudo”即可。这是它。

如果在授予权限后仍然不工作,请尝试运行这些命令:

mkdir ~/.npm-global

npm config set prefix '~/.npm-global'

export PATH=~/.npm-global/bin:$PATH

source ~/.profile

最后用这个命令进行测试

NPM install -g jshint

这对Windows不起作用。

linux用户的简单解决方案,只需在你为npm运行的任何命令前添加sudo

经过长期的研究,我明白了在mac OS中安装angular cli不需要什么,只需使用sudo npm install -g @angular/cli,你的终端会提示密码,输入你的密码,然后继续安装cli。这对我很管用。

安装React需要超级用户级别的权限。在Linux/Unix中,超级用户帐户通常命名为“root”。

要获得超级用户权限,只需在您的终端上运行以下命令:

sudo -i

然后运行命令安装React:

npm install -g create-react-app

但是,reactjs团队鼓励我们使用以下命令,而不是安装全局包。

npx create-react-app app_name