23

当我运行 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

需要注意的依赖项:

"@angular/cli": "~9.1.1",
"@angular/core": "~9.1.1",
"@angular/fire": "^5.1.1",
"firebase": "5.10.1",
"geofirestore": "3.2.3",

包 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"
  }
}

错误屏幕抓取:

在此处输入图像描述

我的应用程序中使用带有 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() };
      })
    );
  }
}
4

7 回答 7

46

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

我发现firebase包不存在。所以我直接复制进去了

“火力基地”:“^7.13.2”,

跑了

npm 安装

它似乎有效:

包.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"
  },

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

于 2020-04-11T10:13:16.753 回答
18

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

解释:

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

ERROR in The target entry-point "@angular/fire" has missing dependencies:
 - firebase/app

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

于 2020-05-18T12:52:08.103 回答
12

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

npm install firebase@latest

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

于 2020-05-14T12:53:23.113 回答
3

在您的应用程序中简单安装 firebase。

npm install firebase --save
于 2020-06-13T15:44:10.423 回答
0

我必须面临同样的错误。

我刚刚安装了 angular cli 第 8 版。我之前的 Angular cli 是 10。

step 1> npm cache clean --force
step 2> npm uninstall -g @angular/cli
step 3> npm cache clean --force
step 4> npm install -g @angular/cli@8.1.0
step 5> ng new project_name
step 6> ng add @angular/fire firebase

希望每件事都能顺利进行。

于 2020-08-09T01:33:49.990 回答
0

运行命令

npm i firebase@7.24.0
于 2021-07-23T12:55:26.223 回答
0

如下所示,安装 Firebase 也对我有用。

npm install firebase
于 2021-08-03T08:16:25.090 回答