UnableToResolveError:无法解析模块`./ node_modules / react-native / packager / src / components` React Native

时间:2022-09-04 10:06:43

I'm building an app using React Native and I got this error.

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

I tried to clear cache and install packages again, but still having issues.

我试图清除缓存并再次安装软件包,但仍然存在问题。

This is the error message from terminal.

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

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

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

And below is the screenshot of iOS simulator.UnableToResolveError:无法解析模块`./ node_modules / react-native / packager / src / components` React Native

以下是iOS模拟器的屏幕截图。

Can anyone please help me?

谁能帮帮我吗?

2 个解决方案

#1


1  

Are you by any chance using babel-plugin-module-resolver as one of your dependencies? Do you happen to have a directory called src with a subdirectory called components? If so I think you might have run into a similar issue that I run into recently, that the app should really look into src/components for the components while it is looking into the wrong path (under node_modules).

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

We were able to temporarily solve the problem by running npm start -- --reset-cache, then refreshing the simulator 2 to 3 times afterwards, although we're now looking into getting rid of bable-plugin-module-resolver altogether.

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

Here is a related issue: https://github.com/tleunen/babel-plugin-module-resolver/issues/138

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

#2


0  

Seems like there is something wrong with how you are importing your "Root" file. Check the current hierarchy and check your relative path to import Root file.

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

#1


1  

Are you by any chance using babel-plugin-module-resolver as one of your dependencies? Do you happen to have a directory called src with a subdirectory called components? If so I think you might have run into a similar issue that I run into recently, that the app should really look into src/components for the components while it is looking into the wrong path (under node_modules).

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

We were able to temporarily solve the problem by running npm start -- --reset-cache, then refreshing the simulator 2 to 3 times afterwards, although we're now looking into getting rid of bable-plugin-module-resolver altogether.

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

Here is a related issue: https://github.com/tleunen/babel-plugin-module-resolver/issues/138

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

#2


0  

Seems like there is something wrong with how you are importing your "Root" file. Check the current hierarchy and check your relative path to import Root file.

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