【问题标题】:UnableToResolveError: Unable to resolve module `./node_modules/react-native/packager/src/components` React NativeUnableToResolveError:无法解析模块`./node_modules/react-native/packager/src/components` React Native
【发布时间】:2017-09-29 10:58:46
【问题描述】:

我正在使用 React Native 构建一个应用,但出现了这个错误。

我尝试清除缓存并再次安装包,但仍然有问题。

这是来自终端的错误信息。

UnhandledPromiseRejectionWarning:未处理的承诺拒绝 (拒绝 id:2):UnableToResolveError:无法解析模块 ./node_modules/react-native/packager/src/components 来自 /Users/andy/Downloads/testapp/index.ios.js: 目录 /Users/andy/Downloads/testapp/node_modules/react-native/packager/src/components 不存在

下面是iOS模拟器的截图。

谁能帮帮我?

【问题讨论】:

  • 你的系统中是否存在这个路径“/Users/andy/Downloads/testapp/node_modules/react-native/packager/src/components”?
  • 找不到,怎么添加?
  • 如果不存在就不用添加了。请尝试更改相对路径。您是否尝试在 index.ios.js 中导入某些内容?
  • import { AppRegistry } from 'react-native' import { Root } from 'app/components' AppRegistry.registerComponent('autospa', () => Root)
  • 这是index.ios.js的内容。

标签: ios npm react-native npm-install react-native-ios


【解决方案1】:

您导入“根”文件的方式似乎有问题。检查当前层次结构并检查您导入根文件的相对路径。

【讨论】:

    【解决方案2】:

    您是否有机会使用 babel-plugin-module-resolver 作为您的依赖项之一?您是否碰巧有一个名为 src 的目录和一个名为 components 的子目录?如果是这样,我认为您可能遇到了我最近遇到的类似问题,即应用程序在查找错误路径(在 node_modules 下)时应该真正查找组件的 src/components。

    我们能够通过运行 npm start -- --reset-cache 暂时解决问题,然后刷新模拟器 2 到 3 次,尽管我们现在正在考虑摆脱 bable-plugin-module-resolver完全一致。

    这是一个相关的问题: https://github.com/tleunen/babel-plugin-module-resolver/issues/138

    【讨论】:

      猜你喜欢
      • 2022-09-25
      • 2020-05-19
      • 1970-01-01
      • 2023-02-16
      • 1970-01-01
      • 2020-05-19
      • 2017-11-12
      • 1970-01-01
      • 2021-12-25
      相关资源
      最近更新 更多