环境搭建
先安装 create-react-native-app 命令
npm install -g create-react-native-app
复制代码
安装完成后创建第一个项目
create-react-native-app AwesomeProject
复制代码
得到一个错误结果,需要降级到npm4。
*******************************************************************************
ERROR: npm 5 is not supported yet
*******************************************************************************
It looks like you're using npm 5 which was recently released.
Create React Native App doesn't work with npm 5 yet, unfortunately. We
recommend using npm 4 or yarn until some bugs are resolved.
You can follow the known issues with npm 5 at:
https://github.com/npm/npm/issues/16991
*******************************************************************************
复制代码
通过命令降级到npm4
npm i npm@4 -g
复制代码
成功后到目录下启动
npm start
复制代码
得到错误,需要修改内核的最大文件数
下午3:22:26: Unable to start server
See https://git.io/v5vcn for more information, either install watchman or run the following snippet:
sudo sysctl -w kern.maxfiles=5242880
sudo sysctl -w kern.maxfilesperproc=524288
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! AwesomeProject@0.1.0 start: `react-native-scripts start`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the AwesomeProject@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /Users/digui/.npm/_logs/2017-12-08T07_22_26_872Z-debug.log
复制代码
执行错误提示中的命令,用来增加系统允许的最大文件数量
sudo sysctl -w kern.maxfiles=5242880
sudo sysctl -w kern.maxfilesperproc=524288
复制代码
再次执行start
npm start
复制代码
发现可以运行成功了。React运行Demo可以使用Facebook提供的Expo App扫码进行显示。