反应导航错误无法解析originModulePath

时间:2020-08-05 16:45:00

标签: react-native expo react-navigation react-navigation-v5

我是新手,对原生语言会做出反应。我一直在尝试建立一个仅包含一些基本页面的应用程序,以进行反应导航的练习,但会不断出错。

Failed building JavaScript bundle.
Unable to resolve "./src/navigation/MainTabs" from "src/navigation/AppNavigator.js"

我正在使用expo并安装了这些npm:

npm install @react-navigation/native
expo install react-native-gesture-handler react-native-reanimated react-native-screens react-native-safe-area-context @react-native-community/masked-view
npm install @react-navigation/stack

到目前为止,这是我的代码:

App.js

import * as React from 'react';
import { NavigationContainer } from '@react-navigation/native';
import AppNavigator from './src/navigation/AppNavigator.js';

const App = () => {
 return (
  <NavigationContainer>
   <AppNavigator />
  </NavigationContainer>
 );
}

export default App;

AppNavigator.js

import * as React from 'react';
import { createStackNavigator } from '@react-navigation/stack';
import MainTabs from './src/navigation/MainTabs';

const Stack = createStackNavigator();

const AppNavigator = () => {
 return (
   <Stack.Navigator>
     <Stack.Screen name='MainTabs' component={MainTabs} />
   </Stack.Navigator>
 );
}

export default AppNavigator;

MainTabs.js

import * as React from 'react';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import PartyMenuScreen from './src/screens/PartyMenuScreen';
import TableMenuScreen from './src/screens/TableMenuScreen';
import VacationMenuScreen from './src/screens/VacationMenuScreen';


const Tabs = createBottomTabNavigator();

const MainTabs = () => {
  return (
    <Tab.Navigator>
     <Tab.Screen name='Party Games' component={PartyMenuScreen} />
     <Tab.Screen name='Table Games' component={TableMenuScreen} />
     <Tab.Screen name='Vacation Games' component={VacationMenuScreen} />
    </Tab.Navigator>
  );
}

export default MainTabs;

我尝试重新安装npm模块并重命名文件路径。除此之外,我不确定该怎么办。我相信这可能与我的依赖关系有关,但是我不确定如何解决它们。

2 个答案:

答案 0 :(得分:0)

您的AppNavigator.js导入路径中有错误

import MainTabs from './src/navigation/MainTabs';

从错误消息中,我假设您在文件夹层次结构中的同一级别拥有AppNavigator.jsMainTabs.js。 将上面的导入内容替换为以下内容:

import MainTabs from './MainTabs';

答案 1 :(得分:0)

解决了问题。 ../用于导入,因为它们位于文件夹中,并且将“选项卡”更改为“选项卡”。