React安装步骤(仅供参考)
1.新建一个文件夹,例如:react
2.进入react文件夹中,按住shift键,右键选择打开PowerShell窗口。
3.输入命令:①npm i -g create-react-app 回车
②create-react-app 回车
③create-react-app demo 回车(demo为项目名称,可任意取)
④cd demo 回车
⑤npm start 回车即安装成功。
如果报错,例如:
events.js:174
throw er; // Unhandled 'error' event
^
Error: spawn cmd ENOENT
at Process.ChildProcess._handle.onexit (internal/child_process.js:240:19)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
Emitted 'error' event at:
at Process.ChildProcess._handle.onexit (internal/child_process.js:246:12)
at onErrorNT (internal/child_process.js:415:16)
at process._tickCallback (internal/process/next_tick.js:63:19)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! demo@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
针对这种错误,解决方法如下
解决方法:1.将react文件夹中的package.json文件打开,将第一段react-scripts更改为如下数字,然后保存:
{ ...............
.................
.................
................(此处省略以上内容)
"react-scripts": "2.1.8"(此处做更改)
},
2.鼠标右键删除node_modules依赖包(可能稍微有点慢)
3.在控制台输入命令:npm install
4.再次输入npm start 回车,即可成功;运行如下:
You can now view demo in the browser.
Local: http://localhost:3000/
On Your Network: http://192.168.146.1:3000/