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

React Native中@react-navigation/stack无StackNavigationProp导出报错求助

问题原因分析及解决建议

核心原因

你遇到的StackNavigationProp找不到的问题,大概率是导航类型的导入路径与实际使用的栈导航器不匹配——你的项目同时安装了@react-navigation/stack和@react-navigation/native-stack两个栈导航器包,但导入类型的路径和你实际用的导航器不一致。另外,依赖里存在重复的masked-view包(@react-native-community/masked-view和@react-native-masked-view/masked-view),可能引发依赖冲突,间接影响类型解析。


解决步骤

第一步:匹配导航器与类型导入路径

先检查项目中创建栈导航器的代码,对应修改类型导入:

  • 如果用的是createNativeStackNavigator(来自@react-navigation/native-stack):

    // AuthStackParams.ts
    import { StackNavigationProp } from '@react-navigation/native-stack'; // 修改导入路径
    import { RouteProp } from '@react-navigation/native';
    
    export type AuthStackParams = {
      Login: undefined;
    };
    
    export type AuthNavProps<T extends keyof AuthStackParams> = {
      navigation: StackNavigationProp<AuthStackParams, T>;
      route: RouteProp<AuthStackParams, T>;
    };
    
  • 如果用的是createStackNavigator(来自@react-navigation/stack):

    1. 清理冗余依赖:运行npm uninstall @react-native-community/masked-view或yarn remove @react-native-community/masked-view,保留官方维护的@react-native-masked-view/masked-view即可
    2. 清除TypeScript缓存:删除项目根目录下的node_modules/.cache文件夹和tsconfig.tsbuildinfo文件(如果存在)
    3. 重启项目:执行expo start -c

额外排查方案

如果上述操作后仍报错:

  • 完全删除node_modules和package-lock.json/yarn.lock,重新执行npm install或yarn install
  • 检查tsconfig.json,确保compilerOptions.moduleResolution设置为node

内容的提问来源于stack exchange,提问作者pelotador.1

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.19 14:00:48