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

报错TypeError: undefined is not an object,求助解决NavigationContainer问题

解决TypeError: undefined is not an object (evaluating '_$$_REQUIRE(...).NavigationContainer')

以下是针对性的修复步骤:

  • 确认@react-navigation/native已正确安装
    先检查项目中是否存在该依赖,执行命令:

    npm list @react-navigation/native
    

    若未安装,根据包管理器执行对应安装命令:

    # npm
    npm install @react-navigation/native
    # yarn
    yarn add @react-navigation/native
    
  • 检查导入语句是否正确
    确保在使用NavigationContainer的组件文件顶部,正确导入该组件:

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

    多数情况下错误源于漏掉此导入,或是导入路径拼写错误。

  • 安装必要的底层依赖
    React Navigation需要额外依赖支持底层功能,执行以下命令安装:

    # npm
    npm install react-native-screens react-native-safe-area-context
    # yarn
    yarn add react-native-screens react-native-safe-area-context
    

    针对iOS平台,需额外执行:

    cd ios && pod install && cd ..
    
  • 清理缓存并重启项目
    缓存异常可能导致模块加载错误,执行命令清理Metro缓存:

    npx react-native start --reset-cache
    

    之后重新启动React Native项目。

  • 检查版本兼容性
    若你的React Native版本偏旧,需确保@react-navigation/native版本与之适配(例如React Native 0.60+对应React Navigation 6+版本),可查看package.json中的版本信息进行调整。

内容的提问来源于stack exchange,提问作者Alperen Kapusuz

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.03 10:25:18