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

升级Firebase 9后导入Firestore的FieldValue报错该如何解决

Firebase 9 非兼容模式 Firestore 类型导入方案

报错原因

Firebase 9 重构为模块化API,废弃了旧版本的全局firebase命名空间设计,非compat模式下不再支持firebase.firestore.xxx的层级访问写法,因此会触发找不到firestore导出成员的报错。

正确实现方式

直接从firebase/firestore包中导入需要的具体类型即可,无需依赖兼容层,你测试验证过的写法就是官方推荐的标准写法:

import { Timestamp, FieldValue } from "firebase/firestore";

export interface ModelTest {
  date?: FieldValue | Timestamp | Date;
}

扩展说明

其他所有Firestore相关的类型、工具方法都可以用相同的直接导入方式使用,比如常用的DocumentReference、QuerySnapshot、WriteBatch等,都不需要再通过旧的命名空间层级调用。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.04 23:27:04