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

Expo Eject后无法从Firestore取数据,调用myApp.firestore()报错

解决Expo Eject后Firestore无法获取数据及myApp.firestore() is not a function错误

你的问题根源在于Firebase v9+采用了模块化API设计,不再支持app.firestore()这种旧的命名空间式调用,必须通过显式导入的Firestore专用函数来操作。结合你的场景,修正方案如下:

修正步骤

  • 补充导入Firestore核心函数:getFirestore和setFirestoreSettings
  • 先初始化App,再通过getFirestore获取Firestore实例
  • 用setFirestoreSettings配置长轮询(注意修正你代码里的拼写错误:experimentsalForceLongPolling → experimentalForceLongPolling)

修正后的完整代码

import { initializeApp } from "firebase/app";
// 新增Firestore相关导入
import { getFirestore, setFirestoreSettings } from "firebase/firestore";

const firebaseConfig = {
  // 填入你的Firebase配置信息
};

const myApp = initializeApp(firebaseConfig);
// 获取Firestore实例
const firestore = getFirestore(myApp);
// 配置长轮询,修正拼写错误
setFirestoreSettings(firestore, { experimentalForceLongPolling: true });

额外说明

Expo Eject后,项目脱离了Expo的封装环境,Firebase SDK的使用必须严格遵循官方模块化规范,不能再混用旧版本的命名空间写法。此外,确保你的Firebase依赖版本是v9及以上,避免版本兼容问题。

内容的提问来源于stack exchange,提问作者Honest Raj

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.01 00:45:36