简体   繁体   English

React Native:无法解析模块。 这些文件都不存在:

[英]React Native: Unable to resolve module. None of these file exist:

I am a beginner in React Native so I apologize if this is a noob question.我是 React Native 的初学者,所以如果这是一个菜鸟问题,我深表歉意。 I am trying to learn using this react navigation article and this about react login example .我正在尝试学习使用这个反应导航文章这个关于反应登录示例 The first article places all the code in App.js while the second one has code in separate pages but is slightly outdated.第一篇文章将所有代码放在App.js中,而第二篇文章将代码放在单独的页面中,但有些过时。 So my plan was to integrate both examples, using the first article's code but in separate pages instead of putting everything in App.js .所以我的计划是整合这两个示例,使用第一篇文章的代码,但在单独的页面中,而不是将所有内容都放在App.js中。

My project structure我的项目结构

The error I got:我得到的错误:

None of these files exist:
  * Screen\drawerScreens\settingsScreen(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
  * Screen\drawerScreens\settingsScreen\index(.native|.android.js|.native.js|.js|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
   6 |
   7 | import HomeScreen from './Screen/drawerScreens/HomeScreen';
>  8 | import SettingsScreen from './Screen/drawerScreens/settingsScreen';
     |                             ^

Some help and tips would be greatly appreciated.一些帮助和提示将不胜感激。 Please let me know if more information is required.如果需要更多信息,请告诉我。 Thanks in advance.提前致谢。

From your project structure, I could see S is caps in SettingsScreen but you have imported as settingsScreen instead of SettingsScreen从您的项目结构中,我可以看到 S 是SettingsScreen中的大写字母,但您已导入为settingsScreen而不是SettingsScreen

so try importing as所以尝试导入为

import SettingsScreen from './Screen/drawerScreens/SettingsScreen';

Have you tried adding the file extension?您是否尝试过添加文件扩展名?

Ex.前任。 './Screen/drawerScreens/settingsScreen.js' './Screen/drawerScreens/settingsScreen.js'

In my case, it was because I copied and dropped the file from Finder (mac).就我而言,这是因为我从 Finder (mac) 复制并删除了文件。 It added an extra space to the end of that folder name.它在该文件夹名称的末尾添加了一个额外的空格。 Erase that space worked.擦除该空间有效。

Check if it is exported as default or export const, if it is the 2nd one, then use import { SettingsScreen } instead of import SettingsScreen检查是否导出为默认或导出常量,如果是第二个,则使用 import { SettingsScreen } 而不是 import SettingsScreen

The solution for me was reset the react-native cache with the command.我的解决方案是使用命令重置react-native缓存。

react-native start --reset-cache

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM