什么可能导致错误Error: EACCES: permission denied, access '/usr/local/lib/node_modules'?
Error: EACCES: permission denied, access '/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
更改您的文件权限…像这样
首先检查谁拥有该目录
ls -la /usr/local/lib/node_modules
它拒绝访问,因为 node_module 文件夹归根用户所有
drwxr-xr-x 3 root wheel 102 Jun 24 23:24 node_modules
所以这需要通过将root更改为您的用户来更改,但首先运行下面的命令以检查您的当前用户 如何通过OS X中的命令行获取活动用户的名称?
id -un要么whoami
id -un
whoami
然后更改所有者
sudo chown -R [owner]:[owner] /usr/local/lib/node_modules
要么
sudo chown -R ownerName: /usr/local/lib/node_modules
sudo chown -R $USER /usr/local/lib/node_modules