You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

React Native Navigation抽屉导航报错:TypeError: Cannot convert undefined value to object

React Native抽屉导航报错:TypeError: Cannot convert undefined value to object

尝试使用React Native Navigation创建抽屉导航时,出现TypeError: Cannot convert undefined value to object错误,已尝试删除重装依赖、重建项目,问题仍未解决。

App.js代码:

import { NavigationContainer } from '@react-navigation/native'
import { createDrawerNavigator } from '@react-navigation/drawer';

import Home from './src/screens/home';

const Drawer = createDrawerNavigator();

const App = () => {
  return (
    <NavigationContainer>
      <Drawer.Navigator>
        <Drawer.Screen name="Home" component={Home} />
      </Drawer.Navigator>
    </NavigationContainer>
  );
}
export default App;

home.js代码:

import { View, Text } from 'react-native';

const Home = () => {
  return(
    <View>
      <Text>Home</Text>
    </View>
  )
};

export default Home;

解决方案:

这个错误通常源于抽屉导航依赖的核心库缺失或配置未完成,按以下步骤排查:

  • 安装必要依赖:抽屉导航需要react-native-gesture-handler和react-native-reanimated支持,执行命令安装:
npm install react-native-gesture-handler react-native-reanimated
  • 完成平台配置:

    • iOS:进入项目ios目录,执行pod install
    • Android:React Native 0.60+版本已支持自动链接,无需额外手动配置;若仍有问题,可检查android/app/build.gradle中是否包含相关依赖
  • 清除项目缓存:

npx react-native start --reset-cache
  • 重新构建项目:
    • iOS:npx react-native run-ios
    • Android:npx react-native run-android

内容的提问来源于stack exchange,提问作者Mehmet Alemdar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.29 23:47:46