在學習React.js 或 React Native 過程當中,有時看着別人的框架或代碼,但老是會出現錯誤,由於React或之中用到的一些包常常更新,有些代碼或教程就顯得過舊了。node
1、平常報錯 'config.h' file not found (每次RN新建一個工程都會出現)react
a. xcode 10.0 file => Project setting => Build Systed => Legacy Build Systedios
b. 再進行以下命令git
1 cd node_modules/react-native/third-party/glog-0.3.4 2 ../../scripts/ios-configure-glog.sh
後來升級到xcode 10.1這個問題就沒有了github
2、Faied to load bundlenpm
查看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-*'
最終我是以下解決的react-native
1.下載boost_1_63.tar.gzxcode
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 便再也不報錯了。
3、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
4、在React 16版本以後, PropTypes 從react包 換到了prop-types 包中,因此想要使用PropTypes 須要這樣:
npm install prop-types --save
import PropTypes from 'prop-types'
5、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