react-navigation / react-navigation

Routing and navigation for your React Native apps
https://reactnavigation.org
23.3k stars 4.97k forks source link

Problem with "createDrawerNavigator" #11973

Open stefunlive0 opened 2 weeks ago

stefunlive0 commented 2 weeks ago

Current behavior

I would like to launch an app on Expo (Android Studio Giraffe) but I have this error

Android Bundling failed 20738ms (C:\Users\My-User\Desktop\Projet01\node_modules\expo\AppEntry.js)
Unable to resolve "@react-navigation/drawer" from "App.jsx"    
Android Bundling failed 31085ms (C:\Users\My-User\Desktop\Projet01\node_modules\expo\AppEntry.js)
Unable to resolve "@react-navigation/drawer" from "App.jsx"

Please can you solve the bug in my code ? :

import * as React from 'react';
import { Button, View, Text } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
import { createBottomTabNavigator } from '@react-navigation/bottom-tabs';
import { createDrawerNavigator } from '@react-navigation/drawer';

function HomeScreen(props) {
  return (
    <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
      <Text>Bonjour</Text>
      <Button title='Contact' onPress={() => {props.navigation.navigate('Contact')}}/>
    </View>
  )
};

function ContactScreen(props) {
  return (
    <View style={{flex: 1, alignItems: 'center', justifyContent: 'center'}}>
      <Text>Contact</Text>
      <Button title='Contact' onPress={() => {props.navigation.navigate('Home')}}/>
    </View>
  )
};

/*
const Stack = createStackNavigator();
const Tabs = createBottomTabNavigator();
*/
const Drawer = createDrawerNavigator();

export default function App() {
  return (
    <NavigationContainer>
      <Drawer.Navigator
        screenOptions={{
          headerStyle: {
            backgroundColor: 'green'
          },
          headerTitleStyle:{
            color: 'white',
            fontWeight: 'bold'
          }
        }}

      >
        <Drawer.Screen name='Home' component={HomeScreen}/>
        <Drawer.Screen name='Contact' component={ContactScreen}/>
      </Drawer.Navigator>
    </NavigationContainer>
  )
};

Thanks in advance

Expected behavior

Normally it works every time when I test new React component. I don't undestand where is the problem

Reproduction

https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAKjgQwM5wEoFNkGN4BmUEI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@react-navigation/native 6.1.17
@react-navigation/drawer 6.6.15
@react-navigation/material-top-tabs 6.6.13
@react-navigation/native-stack
react-native-safe-area-context
react-native-screens
react-native-gesture-handler
react-native-reanimated
react-native-tab-view 3.5.2
react-native-pager-view
react-native
expo
node
npm or yarn
github-actions[bot] commented 2 weeks ago

Hey @stefunlive0! Thanks for opening the issue. It seems that the issue doesn't contain a link to a repro.

The best way to get attention to your issue is to provide an easy way for a developer to reproduce the issue.

You can provide a repro using any of the following:

github-actions[bot] commented 2 weeks ago

Couldn't find version numbers for the following packages in the issue:

Can you update the issue to include version numbers for those packages? The version numbers must match the format 1.2.3.

stefunlive0 commented 2 weeks ago

It's updated

Vikas-singh-0 commented 1 week ago

@stefunlive0 I ran npm install instead of npx expo install and one extra step from documentation, npx expo install react-native-gesture-handler react-native-reanimated

Please try this if it helps.

`// import 'react-native-gesture-handler' import { createDrawerNavigator } from "@react-navigation/drawer"; import { NavigationContainer } from "@react-navigation/native"; import { createNativeStackNavigator } from "@react-navigation/native-stack"; import { Button, StyleSheet, Text, View } from "react-native";

function HomeScreen() { return ( <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>

Home Screen
</View>

); }

function NotificationsScreen({ navigation }) { return ( <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> <Button onPress={() => navigation.goBack()} title="Go back home" /> ); }

const Drawer = createDrawerNavigator();

export default function App() { return (

); }

const Stack = createNativeStackNavigator();

const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#fff", alignItems: "center", justifyContent: "center", }, text: { display: "flex", backgroundColor: "red", height: "1000px", color: "black", }, btn: { width: "100px", height: "100px", backgroundColor: "red", }, }); ` I am using expo to run the app.

stefunlive0 commented 1 week ago

@stefunlive0 I ran npm install instead of npx expo install and one extra step from documentation, npx expo install react-native-gesture-handler react-native-reanimated

Please try this if it helps.

`// import 'react-native-gesture-handler' import { createDrawerNavigator } from "@react-navigation/drawer"; import { NavigationContainer } from "@react-navigation/native"; import { createNativeStackNavigator } from "@react-navigation/native-stack"; import { Button, StyleSheet, Text, View } from "react-native";

function HomeScreen() { return ( <View style={{ flex: 1, alignItems: "center", justifyContent: "center" }}> Home Screen ); }

function NotificationsScreen({ navigation }) { return ( <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}> <Button onPress={() => navigation.goBack()} title="Go back home" /> ); }

const Drawer = createDrawerNavigator();

export default function App() { return ( </Drawer.Navigator> ); }

const Stack = createNativeStackNavigator();

const styles = StyleSheet.create({ container: { flex: 1, backgroundColor: "#fff", alignItems: "center", justifyContent: "center", }, text: { display: "flex", backgroundColor: "red", height: "1000px", color: "black", }, btn: { width: "100px", height: "100px", backgroundColor: "red", }, }); ` I am using expo to run the app.

Hello I have this error : Android Bundling failed 29987ms (C:\Users\My-User\Desktop\Projet01\node_modules\expo\AppEntry.js) Unable to resolve "@react-navigation/drawer" from "App.jsx"

I think that

import { createDrawerNavigator } from "@react-navigation/drawer";

creates the error.

I need to add this :

import 'react-native-gesture-handler'

?

I used also this :

npx expo install react-native-gesture-handler react-native-reanimated