【问题标题】:Unable to resolve "@react-navigation/drawer" from "App.js" React Native无法从 \"App.js\" React Native 解析 \"@react-navigation/drawer\"
【发布时间】:2022-10-24 18:26:27
【问题描述】:

我是 React Native 的新手,我正在尝试使用“导航/菜单栏”,但出现以下错误

Unable to resolve "@react-navigation/drawer" from "App.js"

我安装了但仍然出现同样的错误,我错在哪里?这是我的代码 这是我当前的代码

import * as React from 'react';
import { Button, View } from 'react-native';
import { createDrawerNavigator } from '@react-navigation/drawer';
import { NavigationContainer } from '@react-navigation/native';

function HomeScreen({ navigation }) {
  return (
    <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
      <Button
        onPress={() => navigation.navigate('Notifications')}
        title="Go to notifications"
      />
    </View>
  );
}

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

const Drawer = createDrawerNavigator();

export default function App() {
  return (
    <NavigationContainer>
      <Drawer.Navigator initialRouteName="Home">
        <Drawer.Screen name="Home" component={HomeScreen} />
        <Drawer.Screen name="Notifications" component={NotificationsScreen} />
      </Drawer.Navigator>
    </NavigationContainer>
  );
}

【问题讨论】:

  • @GauravRoy:是什么意思?我怎样才能分享这个?
  • 像世博小吃是一个网站,您可以在其中共享代码的工作示例,p 租赁共享
  • @GauravRoy:当然,先生,那么请给我几分钟

标签: reactjs react-native


【解决方案1】:

确保在运行安装命令时位于主项目文件夹中

npm

npm i react-navigation/drawer

yarn add react-navigation/drawer

尝试在没有@的情况下安装你的包

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-19
    • 1970-01-01
    相关资源
    最近更新 更多