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

React Native+Expo Go中Firestore操作触发内部断言失败错误排查

React Native Expo中Firestore调用addDoc触发内部断言错误解决

核心问题及修复

你遇到的FIRESTORE (10.7.2) INTERNAL ASSERTION FAILED: Unexpected state错误,核心原因是Firestore初始化时未关联已创建的Firebase App实例。

你的Auth模块能正常工作,是因为auth已经绑定了firebaseApp,但getFirestore()调用时未传入App实例,导致Firestore无法正确初始化内部状态。

修复代码

修改Firestore初始化逻辑,将已有的firebaseApp传入getFirestore:

// 原代码
const database = getFirestore();
// 修改后
const database = getFirestore(firebaseApp);

额外排查确认点

  • 导入完整性:你当前导入的getFirestore, addDoc, collection完全满足需求,不存在导入缺失问题。
  • 版本一致性:确保所有firebase相关包(auth、firestore等)版本完全一致,版本不匹配可能引发内部状态异常。
  • Firestore规则验证:可临时将Firestore规则设置为允许写入(仅测试用),排除规则限制的影响:
    rules_version = '2';
    service cloud.firestore {
      match /databases/{database}/documents {
        match /{document=**} {
          allow read, write: if true;
        }
      }
    }
    
  • Expo环境适配:确认使用的是官方firebase npm包,而非@react-native-firebase系列包(Expo Go环境更适配web版Firebase SDK)。

内容的提问来源于stack exchange,提问作者Aston Lamport

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 08:43:16