Angular9:目标入口点“@angular/fire/auth”中的错误缺少依赖项

Ang*_*arM 23 firebase angularfire angular angular9 angular-cli-v9

当我运行 npm run start 时,出现以下有关 firebase 的错误。

技术:Angular 版本 9、Firebase、Firestore、Geofirestore Angular CLI。

错误

ERROR in The target entry-point "@angular/fire/auth" has missing dependencies:
 - firebase/auth
 - firebase/app
Run Code Online (Sandbox Code Playgroud)

需要注意的依赖:

"@angular/cli": "~9.1.1",
"@angular/core": "~9.1.1",
"@angular/fire": "^5.1.1",
"firebase": "5.10.1",
"geofirestore": "3.2.3",
Run Code Online (Sandbox Code Playgroud)

包 json

{
  "name": "project",
  "version": "1.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve -o",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
  },
  "private": true,
  "dependencies": {
    "@agm/core": "^1.1.0",
    "@angular/animations": "~9.1.1",
    "@angular/cdk": "^9.2.0",
    "@angular/common": "~9.1.1",
    "@angular/compiler": "~9.1.1",
    "@angular/core": "~9.1.1",
    "@angular/fire": "^5.1.1",
    "@angular/forms": "~9.1.1",
    "@angular/material": "^9.2.0",
    "@angular/platform-browser": "~9.1.1",
    "@angular/platform-browser-dynamic": "~9.1.1",
    "@angular/platform-server": "^9.1.1",
    "@angular/pwa": "^0.901.1",
    "@angular/router": "~9.1.1",
    "@angular/service-worker": "^9.1.1",
    "@babel/cli": "^7.8.4",
    "@babel/core": "^7.9.0",
    "@babel/preset-env": "^7.9.5",
    "@fortawesome/fontawesome-free": "^5.13.0",
    "@hackages/ngxerrors": "^8.0.0",
    "@kolkov/angular-editor": "^1.1.2",
    "@nguniversal/express-engine": "^9.1.0",
    "@nguniversal/module-map-ngfactory-loader": "^8.2.6",
    "@ngx-meta/core": "^8.0.2",
    "@ngx-pwa/offline": "^9.1.0",
    "@sentry/browser": "^5.15.4",
    "angular-google-map": "0.0.2",
    "animate.css": "^3.7.2",
    "aos": "^2.3.4",
    "basscss": "^8.1.0",
    "basscss-sass": "^4.0.0",
    "chart.js": "^2.9.3",
    "core-js": "^3.6.4",
    "express": "^4.17.1",
    "firebase": "5.10.1",
    "fs-extra": "^9.0.0",
    "geofirestore": "3.2.3",
    "http-server": "^0.12.1",
    "latlon-geohash": "^2.0.0",
    "lodash": "^4.17.15",
    "lozad": "^1.14.0",
    "moment": "^2.24.0",
    "ng2-truncate": "^1.3.17",
    "ngx-google-places-autocomplete": "^2.0.4",
    "ngx-prevent-double-submission": "^0.1.0",
    "rxjs": "~6.5.4",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.901.1",
    "@angular/cli": "~9.1.1",
    "@angular/compiler-cli": "~9.1.1",
    "@angular/language-service": "~9.1.1",
    "@types/jasmine": "~3.5.0",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "^12.11.1",
    "codelyzer": "^5.1.2",
    "jasmine-core": "~3.5.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.4.1",
    "karma-chrome-launcher": "~3.1.0",
    "karma-coverage-istanbul-reporter": "~2.1.0",
    "karma-jasmine": "~3.0.1",
    "karma-jasmine-html-reporter": "^1.4.2",
    "protractor": "~5.4.3",
    "ts-node": "~8.3.0",
    "tslint": "~6.1.0",
    "typescript": "~3.8.3"
  }
}
Run Code Online (Sandbox Code Playgroud)

错误屏幕抓取:

在此处输入图片说明

使用带有 Angular 9 的 firebase / firestore 的应用程序中的代码:

import * as firebase from 'firebase/app';
import * as _geoHash from 'latlon-geohash';
import { AngularFireDatabase } from '@angular/fire/database';
import { AngularFirestore } from '@angular/fire/firestore';
import { Injectable } from '@angular/core';
import { Observable, from, of } from 'rxjs';
import { GeoFirestore } from 'geofirestore';
import { map, take } from 'rxjs/operators';

import { FirebaseService } from '../services/firebase.service';
import { JobModel } from '../models/job.model';
import { StorageService } from '../services/storage.service';
import { UserService } from '../services/user.service';
import { UtilityService } from '../services/utility.service';

@Injectable()
export class JobService extends FirebaseService {
  public geo: any;
  public geofirestore: GeoFirestore;

  constructor(
    public angularFireDatabase: AngularFireDatabase,
    private angularFirestore: AngularFirestore,
    public storageService: StorageService,
    private userService: UserService,
    private utilityService: UtilityService
  ) {
    super(angularFireDatabase);

    const firestore = firebase.firestore();
    firestore.settings({ });
    this.geofirestore = new GeoFirestore(firestore);
  }

  public getCount(): any {
    const adzuna = firebase.firestore().collection('jobsCount').doc('adzuna');
    const hired = firebase.firestore().collection('jobsCount').doc('hired');

    return from(Promise.all([adzuna.get(), hired.get()])
      .then((querySnapshot) => {
        return { adzuna: querySnapshot[0].data(), hired: querySnapshot[1].data() };
      })
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

小智 45

有同样的问题。将我的 package.json 与我前几天工作的另一个项目进行了比较。

我发现 firebase 包不在那里。所以我只是复制了它,

"firebase": "^7.13.2",

跑了

安装

它似乎有效:

包.json:

"dependencies": {
    "@angular/animations": "~9.1.0",
    "@angular/cdk": "^9.2.0",
    "@angular/common": "~9.1.0",
    "@angular/compiler": "~9.1.0",
    "@angular/core": "~9.1.0",
    "@angular/fire": "^6.0.0",
    "@angular/forms": "~9.1.0",
    "@angular/material": "^9.2.0",
    "@angular/platform-browser": "~9.1.0",
    "@angular/platform-browser-dynamic": "~9.1.0",
    "@angular/router": "~9.1.0",
    "firebase": "^7.13.2",
    "rxjs": "~6.5.4",
    "tslib": "^1.10.0",
    "zone.js": "~0.10.2"
  },
Run Code Online (Sandbox Code Playgroud)

现在我看到你有一个旧版本,也许更新可以解决问题?

  • 虽然您的解决方案在某些情况下(也许在大多数情况下)可以工作,但通常这不是手动将包添加到 package.json 的好方法。您可以运行“npm install firebase”来添加该包。请在某处查看我的答案以获取更多详细信息。 (3认同)

Jun*_*aid 18

TL;DR
您需要两个包 ( @angular/fire& firebase) 才能正确运行您的应用程序,然后才能使用 firebase/firestore。
使用ng add @angular/fire&安装它们npm install firebase

解释:

当我提供我的应用程序时,我收到了这个错误。

ERROR in The target entry-point "@angular/fire" has missing dependencies:
 - firebase/app
Run Code Online (Sandbox Code Playgroud)

此错误背后的原因:正确的firebase 角度设置需要两个包@angular/fire& firebase. 我只安装了其中一个使用ng add @angular/fire. 为了成功运行我的项目,我必须firebase使用npm install firebase& 它在此之后工作安装包。


Ene*_*eko 12

只需在您的项目中更新/安装 Firebase(本地,而不是全局)。使用终端转到项目文件夹并执行:

npm install firebase@latest
Run Code Online (Sandbox Code Playgroud)

当前版本的 npm 默认使用 --save 标志,因此它会自动更改 package.json。