【问题标题】:Unable to resolve module `react/lib/ReactComponentTreeHook`无法解析模块`react/lib/ReactComponentTreeHook`
【发布时间】:2018-07-30 16:28:04
【问题描述】:

我正在尝试升级 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

我很困惑。我在 node_modules 的任何地方都找不到任何名为 ReactComponentTreeHook 的库。

我已经尝试删除 node_modules 文件夹并重新安装,nada。我还清除了守望者手表并重置了打包程序缓存。

编辑:我一直遇到似乎源于 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"
  },

再次,经历了清除守望者手表、节点模块、重置包管理器的过程,仍然出现此错误。

编辑 2: 在花了两天时间尝试让这个工作正常运行后,我创建了一个新的空白项目并迁移了我的代码。

【问题讨论】:

  • 您在运行 npm install 时是否收到任何警告?

标签: node.js reactjs react-native


【解决方案1】:

确保 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)

对我来说它有效。

如果您的版本太旧,请按照旧版本文档进行升级。

【讨论】:

    【解决方案2】:

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

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

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

    npm install -save react@16.0.0-alpha.6
    

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

    我认为最近react/lib下的很多模块都被移到了react-dom/lib下,这就是打包器找不到一些模块的原因

    【讨论】:

    • daaaamn!!!它起作用了……但是如何!?我的 package.json 上已经有 "react": "^16.0.0-alpha.6",,删除所有 node_modules、npm install、react-native-git-upgrade、eeeverything,它一遍又一遍地抛出同样的错误,我很生气!!!为什么会发生这个错误?就像 npm 没有从 json 中识别包并且没有安装它......这非常奇怪。谢谢!我不知道为什么没有选择这个答案作为求解器。
    • 我对这个解释并不肯定,但是当您指定 "^", 时,它会将您更新到最新的主要版本(第一个数字)。即 ^1.2.3 将匹配任何 1.x.x 版本,包括 1.3.0,但会推迟到 2.0.0。
    • 哦,因为 alpha.6 不是“稳定”的最后一个版本,因此它会更新到最新的稳定版本?你是这个意思吗?有道理,但是。
    • 我认为依赖解析有点损坏,正如this answer 中所解释的那样。在这种情况下,我会提供要使用的确切版本(不带 ^、~ 等的版本号),而不是让 npm 为我解决。
    【解决方案3】:

    我按照以下步骤操作,它正在工作

    • 删除了 node_modules 文件夹

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

    • npm 安装

    • react-native run-android

    【讨论】:

      猜你喜欢
      • 2017-11-24
      • 2018-09-21
      • 2019-03-10
      • 2021-11-24
      • 2017-03-31
      • 2017-03-31
      • 2018-03-05
      • 1970-01-01
      • 2020-11-05
      相关资源
      最近更新 更多