升级后未知命名模块将本机 0.37 反应为 0.39

Uknown named module after upgrading react native 0.37 to 0.39

我尝试通过以下方式升级我的 react-native 版本(升级的 react 模块和 react-native)

https://facebook.github.io/react-native/docs/upgrading.html

在我 运行 react-native upgrade 之后,我添加了我在 AndroidManifest.xml、MainActivity.java、MainApplication.java、String.xml[=15 中所做的更改=]

我已成功构建 运行 应用程序。但是当资产加载并在我的设备上启动应用程序时,我收到错误消息。

Unknown named module: 'react/lib/createReactNativeComponentClass'

调试时在Chrome上看到这个

Module AppRegistry is not a registered callable module (calling runApplication)

我试图搜索这个问题,但没有找到任何可以帮助我的东西。我唯一没有尝试的是从全新安装开始,看看是否对我有帮助(但我想尽可能避免这种情况)。

还有我的package.json

{
  "name": "MyProject",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node node_modules/react-native/local-cli/cli.js start",
    "test": "jest"
  },
  "dependencies": {
    "react": "^15.4.1",
    "react-native": "^0.39.2",
    "react-native-action-bar": "^1.0.8",
    "react-native-background-timer": "^0.1.3",
    "react-native-drawer": "^2.3.0",
    "react-native-fcm": "^2.3.2",
    "react-native-gifted-spinner": "^0.1.0",
    "react-native-infinite-scroll-view": "^0.4.2",
    "react-native-linear-gradient": "^1.5.15",
    "react-native-maps": "^0.12.2",
    "react-native-pathjs-charts": "0.0.21",
    "react-native-radio-buttons": "^0.13.0",
    "react-native-scrollable-mixin": "^1.0.1",
    "react-native-scrollable-tab-view": "^0.7.0",
    "react-native-swipe-list-view": "^0.3.1",
    "react-native-swiper": "^1.5.3",
    "react-native-vector-icons": "^3.0.0"
  },
  "jest": {
    "preset": "jest-react-native"
  },
  "devDependencies": {
    "babel-jest": "17.0.0",
    "babel-preset-react-native": "1.9.0",
    "jest": "17.0.0",
    "jest-react-native": "17.0.0",
    "react-test-renderer": "15.3.2"
  }
}

在版本 0.37 中一切正常。但是我需要更新,因为我在更改日志中看到了一些我认为有用的修复程序。所以我尝试更新但没有成功。

Vkrm 给了我一个很好的方向 link

One of the changes between 15.3 and 15.4 was that many of the modules under react/lib were moved to react-dom/lib,

考虑到这一点,我尝试将 React 降级到 15.3,结果成功了。但是第三方组件出现了一些错误,react-native 0.39 在 15.4 上效果最好(但在 15.3 下你可能会收到警告)。

我去搜索了更多,找到了这个帖子 whosebug.com/a/41352829/1393695

Delete your node_modules folder and run "npm install" again (or use yarn if you want this step to be fast). Make sure package.json specifies the latest version of React Native that you expect.

之后我再次备份了我的项目并清空了 node_modules 文件夹和 运行 npm install 之后它在 15.4 上运行良好。但是第三方组件出现错误(我更改了)。

所以它可以双向工作,但可能会导致第三方组件出现一些错误。