node.js - 无法解析模块 `react/lib/ReactComponentTreeHook`

标签 node.js reactjs react-native

我正在尝试升级 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 文件夹并重新安装,但没有。我还清除了守望者 watch 并重置了打包器缓存。

编辑:我一直遇到似乎源于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 、 Node 模块、重置包管理器的过程,但仍然出现此错误。

编辑 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)

对我来说它有效。

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

关于node.js - 无法解析模块 `react/lib/ReactComponentTreeHook`,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43743314/

相关文章:

javascript - 状态未按预期更新

css - 视频仅在宽度变化时调整大小,而不是在窗口高度变化时调整

react-native - 是否有用于 react native 的位置设置更改监听器?

node.js - Node 集群: Handle task only to one worker

node.js - SailsCasts 用户模型验证

node.js - 在 nodejs http 请求中获取响应 "ContentType"

angularjs - 跨源请求被阻止 - NodeJs

javascript - React-intl 不改变占位符值

node.js - header 崩溃应用程序并出现错误 TypeError : undefined not an object (evaluating 'theme.label' )

react-native - 使用 React Native 长按透明上下文菜单?