package.json文件內容以下:node
{ "name": "SHRControl", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }, "dependencies": { "eslint": "^4.19.1", "lodash": "^4.17.10", "react": "^16.4.1", "react-native": "^0.56.0", "react-native-accordion": "^1.0.1", "react-native-animatable": "^1.3.0", "react-native-collapsible": "^0.11.3", "react-native-elements": "^0.19.1", "react-native-vector-icons": "^4.6.0", "react-navigation": "^1.5.12", "react-redux": "^5.0.7", "redux": "^3.7.2", "redux-logger": "^3.0.6", "redux-persist": "^5.10.0", "redux-saga": "^0.16.0", "redux-thunk": "^2.3.0" }, "devDependencies": { "babel-jest": "22.4.3", "babel-preset-react-native": "4.0.0", "jest": "22.4.3", "react-test-renderer": "16.3.1" }, "jest": { "preset": "react-native" } }
經過網上查找,找到了出現一樣問題的相關鏈接:
https://stackoverflow.com/que...
https://github.com/facebook/r...
https://github.com/facebook/r...
通過閱讀理解,說是跟babel-preset-react-native
有關,多是版本過低,檢查發現個人babel-preset-react-native
是4.0.0
版本,確實是很低的,如今都是5.0.2
了,因而乎:react
npm install --save babel-preset-react-native@5
從新安裝了babel-preset-react-native
的5.0.2
版本,從新運行,結果仍是下面這樣:ios
error: bundling failed: TypeError: Cannot read property 'bindings' of null at Scope.moveBindingTo (/Users/dp/Documents/React Native/SHRControl/node_modules/@babel/traverse/lib/scope/index.js:978:12) at BlockScoping.updateScopeInfo (/Users/dp/Documents/React Native/SHRControl/node_modules/babel-plugin-transform-es2015-block-scoping/lib/index.js:364:17) at BlockScoping.run (/Users/dp/Documents/React Native/SHRControl/node_modules/babel-plugin-transform-es2015-block-scoping/lib/index.js:330:12) at PluginPass.BlockStatementSwitchStatementProgram (/Users/dp/Documents/React Native/SHRControl/node_modules/babel-plugin-transform-es2015-block-scoping/lib/index.js:70:24) at newFn (/Users/dp/Documents/React Native/SHRControl/node_modules/@babel/traverse/lib/visitors.js:237:21) at NodePath._call (/Users/dp/Documents/React Native/SHRControl/node_modules/@babel/traverse/lib/path/context.js:65:20) at NodePath.call (/Users/dp/Documents/React Native/SHRControl/node_modules/@babel/traverse/lib/path/context.js:40:17) at NodePath.visit (/Users/dp/Documents/React Native/SHRControl/node_modules/@babel/traverse/lib/path/context.js:100:12) at TraversalContext.visitQueue (/Users/dp/Documents/React Native/SHRControl/node_modules/@babel/traverse/lib/context.js:142:16) BUNDLE [ios, dev] ../../index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1), failed.
沒辦法,只好在試下面,刪除整個模塊,從新安裝:git
rm -rf node_modules && npm install
而後:github
1. 從新運行,仍是不行; 2. Xcode上點擊`Product => Clean`清除後再運行仍是不行; 3. 第2步再加上刪掉模擬器上的APP,再運行仍是不行。
最後想到本身再在終端用react-native init RNtest
新建一個項目,運行成功後查看它的package.json文件,檢查依賴模塊devDependencies
發現不同,而後果斷把出問題的項目依賴"devDependencies"換成:npm
{ "babel-jest": "23.4.0", "babel-preset-react-native": "5.0.2", "jest": "23.4.1", "react-test-renderer": "16.4.1" }
而後再經過上面的三步驟進行嘗試,仍是紅屏,差點崩潰😖。json
最後放大超:點擊Xcode的Product
再按鍵盤上的【option】鍵,而後出現Clean Build Folder
並點擊,再彈框點擊Clean
,清理結束後,而且刪掉模擬器上舊的APP,運行,經過了。redux
a. babel-preset-react-native
更新到最新,例如:react-native
{ "babel-jest": "23.4.0", "babel-preset-react-native": "5.0.2", "jest": "23.4.1", "react-test-renderer": "16.4.1" }
b. 刪除React Native全部模塊從新安裝babel
rm -rf node_modules && npm install
c. 點擊Xcode的Product
再按鍵盤上的【option】鍵,而後出現Clean Build Folder
並點擊,再彈框點擊Clean
,清理結束後,而且刪掉模擬器上舊的APP。d. 從新運行。