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

使用原生JS连接Firestore时报错Service firestore is not available如何解决

问题根因

你遇到的报错由两个明显的配置错误导致:

  • 不同Firebase SDK组件版本不匹配
  • HTML中脚本引入路径错误
修复步骤
  1. 统一所有Firebase SDK的版本号
    两个文件引入的SDK版本分别是9.0.0和9.0.1,跨版本混用会导致服务注册失败,全部调整为同一个版本即可,比如统一用9.0.1:
    修改index.js的导入语句:
import app from './firebase.js'
// 版本号和firebase.js保持一致,改为9.0.1
import { getFirestore } from 'https://www.gstatic.com/firebasejs/9.0.1/firebase-firestore.js'
const db = getFirestore(app)
  1. 修正HTML中的脚本引入路径
    你当前把index.html本身作为模块引入,属于路径填写错误,改为引入你的业务脚本index.js:
<!DOCTYPE html>
....
<script type="module" src="index.js"></script>
可选校验项

如果修复上述两项后仍有报错,可以再确认:

  • Firebase控制台中你的项目已正常启用Cloud Firestore服务
  • Firestore安全规则已放开对应权限(你提到控制台可正常读写,本项基本无问题)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.06 05:27:00