npm安装create-react-app出现“Error: EACCES: permission denied”的解决办法

开发环境

mac 10.12.4、node v6.10.2、npm  v3.10.10

问题描述

使用npm命令

npm install -g create-react-app

安装create-react-app的时候出现以下错误:

npm ERR! Darwin 16.5.0

npm ERR!argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "create-react-app"

npm ERR!node v6.10.2

npm ERR!npm  v3.10.10

npm ERR!path ../lib/node_modules/create-react-app/index.js

npm ERR!code EACCES

npm ERR!errno -13

npm ERR!syscall symlink


npm ERR! Error: EACCES: permission denied, symlink '../lib/node_modules/create-react-app/index.js' -> '/usr/local/bin/create-react-app'

npm ERR!     at Error (native)

npm ERR!  { Error: EACCES: permission denied, symlink '../lib/node_modules/create-react-app/index.js' -> '/usr/local/bin/create-react-app'

npm ERR!     at Error (native)

npm ERR!   errno: -13,

npm ERR!   code: 'EACCES',

npm ERR!   syscall: 'symlink',

npm ERR!   path: '../lib/node_modules/create-react-app/index.js',

npm ERR!   dest: '/usr/local/bin/create-react-app' }

npm ERR! 

npm ERR! Please try running this command again as root/Administrator.


npm ERR! Please include the following file with any support request:

npm ERR!     /Users/wudengwei/npm-debug.log

问题原因

npm的错误提示已经指出了原因:Error: EACCES: permission denied (权限不够)

并给出了建议 

Please try running this command again as root/Administrator.(使用管理员权限)

问题解决

使用加上sudo的npm命令(sudo: 申请root 权限

sudo npm install -g create-react-app


总结

代码执行出错,都会有相应的错误提示。它或多或少交代了问题的原因,但解决方法就需要我们思考了。


你可能感兴趣的:(Web前端)