Uncaught Error: Cannot find module './recipes' in React Native
Uncaught Error: Cannot find module './recipes' in React Native
所以我尝试从 ./recipes 文件夹中导入文件,但它一直显示找不到模块“./recipes”的错误
这是我的 App.js:
import React, { Component } from "react";
import Home from "./Screens/Home";
import { Ampalaya, AdobongSitaw } from "./recipes";
<NavigationContainer>
<StatusBar style="auto" />
<Stack.Navigator>
<Stack.Screen
name="Home"
component={Home}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Ampalaya"
component={Ampalaya}
options={{
headerRight: (props) => <Logo {...props} />,
headerTitle: "Back",
}}
/>
<Stack.Screen
name="AdobongSitaw"
component={AdobongSitaw}
options={{
headerRight: (props) => <Logo {...props} />,
headerTitle: "Back",
}}
/>
</Stack.Navigator>
</NavigationContainer>
所有这些文件都存在于它们的透视文件夹中。仍然找不到解决方案。这是我的文件夹结构:
enter image description here
请在导入主屏幕时尝试导入它。
import Ampalaya from "./recipes/Ampalaya";
import AdobongSitaw from "./recipes/AdobongSitaw";
实现导入方式的唯一方法是制作配方模块。
在您的食谱文件夹中创建 index.js。
将所有组件导入文件。
导出包含所有组件的模块。
//index.js
import Ampalaya from "./Ampalaya";
import AdobongSitaw from "./AdobongSitaw";
export { Ampalaya, AdobongSitaw };
导入您的操作方式:
import { Ampalaya, AdobongSitaw } from "./recipes";
所以我尝试从 ./recipes 文件夹中导入文件,但它一直显示找不到模块“./recipes”的错误
这是我的 App.js:
import React, { Component } from "react";
import Home from "./Screens/Home";
import { Ampalaya, AdobongSitaw } from "./recipes";
<NavigationContainer>
<StatusBar style="auto" />
<Stack.Navigator>
<Stack.Screen
name="Home"
component={Home}
options={{ headerShown: false }}
/>
<Stack.Screen
name="Ampalaya"
component={Ampalaya}
options={{
headerRight: (props) => <Logo {...props} />,
headerTitle: "Back",
}}
/>
<Stack.Screen
name="AdobongSitaw"
component={AdobongSitaw}
options={{
headerRight: (props) => <Logo {...props} />,
headerTitle: "Back",
}}
/>
</Stack.Navigator>
</NavigationContainer>
所有这些文件都存在于它们的透视文件夹中。仍然找不到解决方案。这是我的文件夹结构:
enter image description here
请在导入主屏幕时尝试导入它。
import Ampalaya from "./recipes/Ampalaya";
import AdobongSitaw from "./recipes/AdobongSitaw";
实现导入方式的唯一方法是制作配方模块。
在您的食谱文件夹中创建 index.js。
将所有组件导入文件。
导出包含所有组件的模块。
//index.js
import Ampalaya from "./Ampalaya";
import AdobongSitaw from "./AdobongSitaw";
export { Ampalaya, AdobongSitaw };
导入您的操作方式:
import { Ampalaya, AdobongSitaw } from "./recipes";