首页 文章

无法解析模块`react / lib / ReactComponentTreeHook`

提问于
浏览
1

我正在尝试升级React Native,我遇到了以下问题:

error: bundling: UnableToResolveError: Unable to resolve module `react/lib/ReactComponentTreeHook` from `/Users/anthony/dev/apptova-react/node_modules/react-native/Libraries/Performance/Systrace.js`: Module does not exist in the module map or in these directories:
  /Users/anthony/dev/apptova-react/node_modules/react-native/node_modules/react/lib
,   /Users/anthony/dev/apptova-react/node_modules/react/lib

我'm so confused. I can'在 node_modules 中找到任何名为ReactComponentTreeHook的库 .

我已经尝试删除 node_modules 文件夹并重新安装,nada . 我还清除了守望者 Watch 并重置了打包器缓存 .

EDIT: 我一直在遇到似乎源于react-native-maps的问题,所以我重新调整回工作稳定版本,卸载react-native-maps,然后运行react-native-git-upgrade(再次) .

现在我得到:

error: bundling: UnableToResolveError: Unable to resolve module `react/lib/ReactDebugCurrentFrame` from `/Users/anthony/dev/apptova-react/node_modules/react-native/Libraries/Renderer/src/renderers/shared/stack/reconciler/ReactCompositeComponent.js`: Module does not exist in the module map or in these directories:
  /Users/anthony/dev/apptova-react/node_modules/react-native/node_modules/react/lib
,   /Users/anthony/dev/apptova-react/node_modules/react/lib

我只是想尝试最新的,我的package.json依赖项很简单,所以我认为它与第三方代码库没有冲突:

"dependencies": {
    "react": "15.4.1",
    "react-native": "^0.43.1",
    "react-native-drawer": "^2.3.0"
  },
  "devDependencies": {
    "babel-jest": "18.0.0",
    "babel-plugin-transform-flow-strip-types": "^6.21.0",
    "babel-preset-react-native": "1.9.1",
    "deepmerge": "^1.3.2",
    "flow-bin": "^0.37.4",
    "jest": "18.0.0",
    "react-test-renderer": "15.4.1"
  },

再次,完成了清除守望者 Watch ,节点模块,重置包管理器的过程,仍然得到这个错误 .

EDIT 2: 在花了两天时间试图让这个工作起来后,我创建了一个新的空白项目并将我的代码迁移过来 .

3 回答

  • 2

    如果您没有react-native版本所需的正确版本的响应,也可能发生这种情况 . 如果是这种情况,运行 npm install 时会收到类似这样的警告 .

    npm WARN react-native@0.43.4 requires a peer of react@16.0.0-alpha.6 but none was installed.
    

    要解决此问题,请通过运行以下命令停止react packager并升级react版本

    npm install -save react@16.0.0-alpha.6
    

    现在,重新运行应用程序,希望问题会消失 .

    我想最近在react / lib下的许多模块被转移到react-dom / lib,这就是为什么打包器找不到一些模块的原因

  • 0

    我按照以下步骤进行操作

    •删除了node_modules文件夹

    •用“react”替换^ 16.0.0-alpha.6:“16.0.0-alpha.3”

    •npm安装

    •react-native run-android

  • 2

    确保package.json文件中的版本是您想要的版本 .

    例如,“react-native:^ 0.43.3”与“react-native:0.43.3”不同 .

    清理并重新安装一切 .

    如果错误仍然存在,那么尝试安装react-native-git-upgrade

    $ npm install -g react-native-git-upgrade
    

    然后跑

    $ react-native-git-upgrade x.y.z(version you want to upgrade to)
    

    对我来说它有效 .

    如果您的版本太旧,那么您应该按照旧版本文档进行升级 .

相关问题