UnableToResolveError: Unable to resolve module `./node_modules/react-native/packager/src/components` React Native

UnableToResolveError: Unable to resolve module `./node_modules/react-native/packager/src/components` React Native

我正在使用 React Native 构建应用程序,但遇到此错误。

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

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

UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): UnableToResolveError: Unable to resolve module ./node_modules/react-native/packager/src/components from /Users/andy/Downloads/testapp/index.ios.js: Directory /Users/andy/Downloads/testapp/node_modules/react-native/packager/src/components doesn't exist

下面是iOS模拟器的截图。

谁能帮帮我?

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

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

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

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