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

Firebase图片上传成功却触发ReferenceError: doc未定义错误求助

问题分析:ReferenceError: doc is not defined

错误详情

Unhandled Runtime Error
ReferenceError: doc is not defined

Source
components\Modal.js (42:18) @ updateDoc

  40 | await uploadString(imageRef, selectedFile, "data_url").then(async (snapshot) => {
  41 |     const downloadURL = await getDownloadURL(imageRef);
> 42 |     await updateDoc(doc(db, 'posts', docRef.id), {
     |          ^
  43 |         image: downloadURL
  44 |     })
  45 | });
Call Stack
async uploadPost

上传图片后弹出上述错误,但图片已成功上传至Firebase存储桶中。

解决方法

  • 检查Modal.js文件顶部,确认是否从Firebase Firestore库中正确导入了doc方法:
    • 若使用Firebase v9+模块化语法,需添加:
      import { doc, updateDoc } from "firebase/firestore";
      
    • 若使用旧版本命名空间语法,需确保已正确引用doc:
      const { doc, updateDoc } = firebase.firestore();
      
  • 确认导入语句拼写无误,doc没有被遗漏或写错
  • 图片上传成功说明Storage相关逻辑正常,问题仅出在Firestore的doc方法未定义,重点排查Firestore的导入和初始化步骤

内容的提问来源于stack exchange,提问作者Ved-code

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.29 19:10:13