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

使用Firebase实时数据库开发登录页遇模块解析错误求助

解决Firebase v9导入报错:Uncaught TypeError: Failed to resolve module specifier "firebase/app"

问题场景

开发基于Firebase实时数据库的网页登录页时,已通过npm安装Firebase Node模块,但浏览器运行时始终抛出错误:

Uncaught TypeError: Failed to resolve module specifier "firebase/app". Relative references must start with either "/", "./", or "../"

已尝试的无效操作

  • 清除npm缓存并重新安装Firebase
  • 修改导入路径为./firebase/app
  • 重建整个项目
  • 考虑过使用CDN方案,但因依赖VS Code自动补全支持,更倾向于使用Node Modules

最终解决方案

问题根源在于Firebase v9强制要求搭配模块打包器(如Webpack、Vite或Parcel)使用,直接在浏览器环境中引用Node模块路径会导致解析失败。启用模块打包器后,即可正常使用import { initializeApp } from "firebase/app"这类标准导入语法,同时保留VS Code的自动补全功能。

内容的提问来源于stack exchange,提问作者Mr. Mylad

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.25 11:14:58