React Native Cannot read property 'bindings' of null (null)) 解決!

React Native在iOS模擬器上運行加載文件時出現 Failed to load bundle(http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false) with error:(/Users/dp/Documents/React Native/SHRControl/App.js: Cannot read property 'bindings' of null (null))錯誤,必現!

Simulator Screen Shot - iPhone X - 2018-07-18 at 09.48.52.png
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-native4.0.0版本,確實是很低的,如今都是5.0.2了,因而乎:react

npm install --save babel-preset-react-native@5

從新安裝了babel-preset-react-native5.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. 從新運行。

相關文章
相關標籤/搜索