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

当Mac OS通过 npm 安装 jest-cli 报错,警告文字为:checkPermissions Missing write access to /usr/local/lib/node_modules

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:
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! The operation was rejected by your operating system.
npm ERR! It is likely you do not have the permissions to access this file as the current user
npm ERR! 
npm ERR! If you believe this might be a permissions issue, please double-check the
npm ERR! permissions of the file and its containing directories, or try running
npm ERR! the command again as root/Administrator (though this is not recommended).

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/wind/.npm/_logs/2019-04-01T02_56_36_524Z-debug.log

怎么办?

报错原因:
npm 的安装权限不足

解决办法:
在安装命令前加上 sudo,根据提示输入密码即可。

gn:react-native-sql wind$ sudo npm install -g jest-cli
Password:
/usr/local/bin/jest -> /usr/local/lib/node_modules/jest-cli/bin/jest.js
+ [email protected]
added 487 packages from 388 contributors in 13.879s

你可能感兴趣的:(checkPermissions Missing write access to /usr/local/lib/node_modules)