如何通过终端安装 create-react-app

How to install create-react-app through terminal

我正在通过终端安装 create-react-app。我查看了node.js版本是4.5.0,高于要求here。 npm 的版本是 2.15.9。然后我输入命令npm install -g create-react-app,出现了这样的错误信息:

npm ERR! tar.unpack untar error /Users/xiufenxu/.npm/create-react-app/0.6.0/package.tgz
npm ERR! Darwin 16.0.0
npm ERR! argv "/usr/local/bin/node" "/usr/local/bin/npm" "install" "-g" "create-react-app"
npm ERR! node v4.5.0
npm ERR! npm  v2.15.9
npm ERR! path /usr/local/lib/node_modules/create-react-app
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall mkdir

npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/create-react-app'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/create-react-app']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'mkdir',
npm ERR!   path: '/usr/local/lib/node_modules/create-react-app',
npm ERR!   fstream_type: 'Directory',
npm ERR!   fstream_path: '/usr/local/lib/node_modules/create-react-app',
npm ERR!   fstream_class: 'DirWriter',
npm ERR!   fstream_stack:
npm ERR!    [ '/usr/local/lib/node_modules/npm/node_modules/fstream/lib/dir-writer.js:35:25',
npm ERR!      '/usr/local/lib/node_modules/npm/node_modules/mkdirp/index.js:47:53',
npm ERR!      'FSReqWrap.oncomplete (fs.js:82:15)' ] }
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/xiufenxu/Documents/UM courses/Fall 2016/CSCI 5117/npm-debug.log

我想知道为什么会出现这样的错误。有没有人可以帮我解决这个问题?非常感谢!

sudo npm install -g create-react-app

你运行它是一个没有 root 权限的用户

重新启动我的电脑为我修复了它