检查node是否安装
没有安装可到官网进行下载 Node.js
安装完成后在终端输入npm -v检查是否安装完成
安装react
设置npm源
npm config set registry https://registry.npm.taobao.org --global
npm ERR! code EACCES
npm ERR! syscall mkdir
npm ERR! path /usr/local/etc
npm ERR! errno -13
npm ERR! Error: EACCES: permission denied, mkdir '/usr/local/etc'
npm ERR! [Error: EACCES: permission denied, mkdir '/usr/local/etc'] {
npm ERR! errno: -13,
npm ERR! code: 'EACCES',
npm ERR! syscall: 'mkdir',
npm ERR! path: '/usr/local/etc'
npm ERR! }
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.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/zhanwei/.npm/_logs/2020-04-29T15_10_56_578Z-debug.log
出现以下错误说明权限不足
解决权限不足的方法
打开终端输入下列命令
mkdir .npm-global
npm config set prefix '~/.npm-global'
export PATH=~/.npm-global/bin:$PATH
PM_CONFIG_PREFIX=~/.npm-global
解决后设置npm源
npm config set registry https://registry.npm.taobao.org --global
npm config set disturl https://npm.taobao.org/dist --global
安装全局create-react-app
npm install -g create-react-app
出现下面情况说明安装成功
npm WARN deprecated tar@2.2.2: This version of tar is no longer supported, and will not receive security updates. Please upgrade asap.
/Users/yangkui/.npm-global/bin/create-react-app -> /Users/yangkui/.npm-global/lib/node_modules/create-react-app/index.js
+ create-react-app@4.0.3
added 67 packages from 25 contributors in 2.814s
创建项目
cd到你要创建项目的文件夹内输入命令
create-react-app 项目名称
运行项目
cd到刚创建的项目文件夹内运行
npm start
出现以下节目什么运行成功
完毕