React Native 日常报错

  在学习React.js 或 React Native 过程中,有时看着别人的框架或代码,但总是会出现错误,因为React或之中用到的一些包经常更新,有些代码或教程就显得过旧了。

一、日常报错 'config.h' file not found (每次RN新建一个工程都会出现)

 a. xcode 10.0 file => Project setting => Build Systed => Legacy Build Systed

 b. 再进行如下命令

1 cd node_modules/react-native/third-party/glog-0.3.4
2 ../../scripts/ios-configure-glog.sh

后来升级到xcode 10.1这个问题就没有了

二、Faied to load bundle

查看stackoverflow: 尝试解决
或者看看这个issue: https://github.com/facebook/react-native/issues/18962
或者可以试试如下清除
1.Clear watchman watches: 'watchman watch-del-all'
2.Delete the node_modules: 'rm -rf node_modules && npm install'
3.Reset Metro Bundler cache: 'rm -rf /tmp/metro-bundler-cache-*' or 'npm start -- --reset-cache'
4.Remove haste cache: 'rm -rf /tmp/haste-map-react-native-packager-*'

 最终我是如下解决的

 1.下载boost_1_63.tar.gz

 2. mac电脑命令行 open ~

 3. 将下载好的文件替换掉.rncache文件夹下的boost_1_63_0.tar.gz

 4.在react native工程下执行npm install -g react-native-git-upgrade && react-native-git-upgrade

 5.react-native run-ios (再不行就重启电脑执行这个命令)

 6.结果发现上述情况有时成功,有时还是怎么都解决不了,于是将 xcode 的从10.0升级到了10.1,重新 react-native run-ios 便不再报错了。

 三、import {Navigator} from 'react-native'报错: no such file or directory

react-native 0.44 版本以后 Navigator 需要从 react-native-deprecated-custom-components 导入。如果还报错如没有找到.jsbundle文件等,完全关闭一下模拟器,再重新 react-native run-ios 

 四、在React 16版本之后, PropTypes 从react包 换到了prop-types 包中,所以想要使用PropTypes 需要这样:

   npm install prop-types --save 

   import PropTypes from 'prop-types' 

五、Undefined is no an object (evaluating _reactNative.View.propTypes.style)

  google到这个issue找到解决: https://github.com/facebook/react-native/issues/16542  (将 View.PropTypes.style 改成 ViewPropTypes.style )

  如果还报错则需要一个引入: import {ViewPropTypes} from 'react-native',  参考这个链接下 husnaingoldev 的回答 https://github.com/facebook/react-native/issues/14032

 
原文地址:https://www.cnblogs.com/buerjj/p/10394651.html