1、升级node(对安装包安装或者低版本的如6.11.4不生效)
1>查看node版本,没安装的请先安装;
$ node -v
2>清除node缓存;
$ sudo npm cache clean -f
3>安装node版本管理工具'n';
$ sudo npm install n -g
4>使用版本管理工具安装指定node或者升级到最新node版本;
$ sudo n stable (安装node最新版本)
$ sudo n 8.9.4 (安装node指定版本8.9.4)
5>使用node -v查看node版本,如果版本号改变为你想要的则升级成功。
2、对于未知安装的node,卸载删除重新安装
which node
/usr/local/bin/node
可以找到对应的文件夹,可直接删除
3、执行brew install node后,报错:
node-7.6.0 already installed, it's just not linked
执行
// 给当前用户添加目录权限
sudo chown -R $(whoami) /usr/local
brew link --overwrite node
brew postinstall node
4、执行npm i报错:
npm ERR! fatal: unable to access 'https://git@github.com/react-native-community/react-native-camera.git/': Empty reply from server
这段脚本执行区git拉取代码所用到(默认用ssh)的端口被禁止使用.应该改用https的方式进行下载.
执行命令:
git config --global url."https://".insteadOf git://
再执行 npm i可能还会报错如下:
npm ERR! fatal: unable to access 'https://git@github.com/react-native-community/react-native-camera.git/': LibreSSL SSL_read: SSL_ERROR_SYSCALL, errno 54
设置正确的代理ip:
解决被墙问题参考:https://juejin.im/post/5b5196a5e51d451946094309
局部代理:
git config --global https.proxy https://127.0.0.1:1080
git config --global http.proxy http://127.0.0.1:1087
全局设置代理:
export http_proxy=http://127.0.0.1:1087;export https_proxy=http://127.0.0.1:1087;
再执行npm 可能出现报错:
WARN registry Unexpected warning for https://registry.npm.taobao.org/: Miscellaneous Warning ECONNRESET: request to https://registry.npm.taobao.org/@babel%2fhelper-remap-async-to-generator failed, reason: read ECONNRESET
WARN registry Using stale package data from https://registry.npm.taobao.org/ due to a request error during revalidation.
WARN registry Unexpected warning for https://registry.npm.taobao.org/: Miscellaneous Warning ECONNRESET: request to https://registry.npm.taobao.org/@babel%2fhelper-wrap-function failed, reason: read ECONNRESET
执行:
rm ./package-lock.json
rm -r ./node_modules
npm cache clear —force
再执行npm 可能出现报错:
npm ERR! network request to https://registry.npm.taobao.org/fbjs-scripts/download/fbjs-scripts-0.8.3.tgz failed, reason: read ECONNRESET
执行:
npm install -g npm
对于终端出现的警告:
npm WARN react-native@0.56.0 requires a peer of react@16.4.1 but none is installed. You must install peer dependencies yourself.
执行:
npm install -save react@~16.4.1
执行:npm i
拉取jsbundle:
react-native bundle --entry-file index.js --bundle-output ./ios/index.bundle --platform ios --assets-dest ./ios --dev false
如果出现报错:
Cannot read property 'bindings' of null
// babel-preset-react-native版本过低造成,React Native 0.56.0 需要 babel-preset-react-native@5.0.0 版本
执行:
npm remove babel-preset-react-native
npm install --save babel-preset-react-native@5.0.0
需要删除并重新安装:
执行:
rm -rf node_modules && npm install
因为当前的项目需要兼容之前的老版本,替换以下路径的文件夹:
iloop_boss/node_modules/react-native-camera/ios
iloop_boss/node_modules/react-native/Libraries/Renderer/shims
替换完成后删除takeSnapshot.js、TouchHistoryMath.js文件
打开项目工程,运行成功报错:
React Native version mismatch.
JavaScript version: 0.56.0
Native version: 0.54.2
Make sure that you have rebuilt the native code. If the problem persists try clearing the Watchman and packager caches with `watchman watch-del-all && react-native start --reset-cache`.
执行:
npm install --save react-native@0.54.2
react-native upgrade
解决!
5、编译运行报错:
Module AppRegistry is not a registered callable module
不知道是什么问题,在模拟器会报错,在真机上可以正常运行,重新npm , 清除缓存一直到最后重启电脑才解决
报错持续更新。。。。