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

执行ng serve时firebase/compat/index.d.ts报错,Angular 12版本兼容问题

Angular 12 下 Firebase 包依赖兼容问题

为适配 Angular 12 版本,已尝试将 @angular/fire 从 v7.4.1 降级至 v7.0,但仍出现 Firebase 相关编译错误。

package.json 依赖配置

"dependencies": {
    "@angular/animations": "^12.0.0",
    "@angular/cdk": "^12.0.0",
    "@angular/common": "~12.0.0",
    "@angular/compiler": "~12.0.0",
    "@angular/core": "~12.0.0",
    "@angular/fire": "^7.4.1",
    "@angular/forms": "~12.0.0",
    "@angular/localize": "~12.0.0",
    "@angular/material": "^12.0.0",
    "@angular/platform-browser": "~12.0.0",
    "@angular/platform-browser-dynamic": "~12.0.0",
    "@angular/router": "~12.0.0",
    "@grammarly/editor-sdk": "^1.8.4",
    "@ng-bootstrap/ng-bootstrap": "^10.0.0",
    "@popperjs/core": "^2.11.5",
    "@stripe/stripe-js": "^1.35.0",
    "angularx-social-login": "^4.1.0",
    "aws-sdk": "^2.1134.0",
    "bootstrap": "^5.1.3",
    "crypto-js": "^4.1.1",
    "docx": "^7.3.0",
    "file-saver": "^2.0.5",
    "firebase": "^9.9.3",
    "html-to-text": "^8.2.0",
    "jquery": "^3.6.0",
    "js-file-download": "^0.4.12",
    "moment": "^2.29.3",
    "ng-circle-progress": "^1.6.0",
    "ngx-autosize": "^2.0.2",
    "ngx-bootstrap": "^7.0.0",
    "ngx-mask": "^14.0.3",
    "ngx-stripe": "^12.8.2",
    "ngx-toastr": "^14.3.0",
    "ngx-ui-loader": "^11.0.0",
    "popper.js": "^1.16.1",
    "rxjs": "~6.6.0",
    "tslib": "^2.1.0",
    "util": "^0.12.4",
    "zone.js": "~0.11.4"
  }

错误信息

编译时出现以下类型错误:

  • node_modules/@angular/fire/firebase.app.module.d.ts:2:22 - error TS2305: Module '"firebase/app"' has no exported member 'FirebaseApp'.
  • 类似地,找不到 FirebaseOptions、FirebaseConfig 等 Firebase 核心导出成员

解决方案

问题根源是 @angular/fire 与 firebase 版本不兼容,Angular 12 需严格匹配对应版本:

  1. 卸载现有冲突包:
    npm uninstall @angular/fire firebase
    
  2. 安装 Angular 12 兼容的指定版本:
    npm install @angular/fire@7.0.0 firebase@9.0.2
    
  3. 清理缓存并重新安装依赖:
    # macOS/Linux
    rm -rf node_modules package-lock.json && npm install
    # Windows
    rmdir /s /q node_modules && del package-lock.json && npm install
    
  4. 重新编译项目:
    ng build
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.24 04:17:12