Angular9: ERROR in The target entry-point "@angular/fire/auth" has missing dependencies
Asked Answered
P

8

24

When I run npm run start I get the below error regarding firebase.

Tech: Angular version 9, Firebase, Firestore, Geofirestore Angular CLI.

Error:

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

Dependencies to note:

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

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

Error Screen grab:

enter image description here

Code from my app using firebase / firestore with Angular 9:

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() };
      })
    );
  }
}
Pervert answered 9/4, 2020 at 21:3 Comment(2)
Could you include a sample of where you import from @angular/fire/auth?Lucillalucille
@Lucillalucille I've added sample code from my app to bottom of the question. Let me know if you need anything else. Thank you.Pervert
S
47

Had the same problem. Compared my package.json with a different project of mine that worked just the other day.

I found that the firebase package was not there. So I just copied it in,

"firebase": "^7.13.2",

ran

npm install

and it seems to work:

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

Now I see you have an older version, maybe updating that will solve the problem?

Seed answered 11/4, 2020 at 10:13 Comment(1)
Although your solution will work in some cases, maybe most cases but generally this is not a good approach to manually add packages into your package.json. You can instead run npm install firebase to add that package. Check my answer down somewhere for more details.Rough
R
20

TL;DR
You need two packages (@angular/fire & firebase) to properly run your app and then to use firebase/firestore.
Install them using ng add @angular/fire & npm install firebase

Explanation:

I was getting this error when I served my app.

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

Reason behind this error: A proper firebase angular setup needs two packages @angular/fire & firebase. I only had one of them installed using ng add @angular/fire. In order to successfully run my project, I had to install the firebase package using npm install firebase & it worked after this.

Rough answered 18/5, 2020 at 12:52 Comment(0)
J
12

Just update/install Firebase in your project (locally, not globally). Using the terminal go to the project folder and execute:

npm install firebase@latest

Current versions of npm uses --save flag as default, so it will change package.json automatically.

Jam answered 14/5, 2020 at 12:53 Comment(0)
D
3

Simple install firebase in your application.

npm install firebase --save
Defeasance answered 13/6, 2020 at 15:44 Comment(0)
P
0

I Have to been facing same error.

I just installed angular cli 8th version. My previous angular cli was 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/[email protected]
step 5> ng new project_name
step 6> ng add @angular/fire firebase

Hope so every thing works well.

Prey answered 9/8, 2020 at 1:33 Comment(1)
Commands should be formatted by surrounding them with backticks. An ordered list can be formatted by placing a number and a period followed by a space at the beginning of the row and incrementing the number with each new line in the list.Jezreel
D
0

run the command

npm i [email protected]
Dedie answered 23/7, 2021 at 12:55 Comment(0)
P
0

Installing Firebase, like below, worked for me too.

npm install firebase
Protozoal answered 3/8, 2021 at 8:16 Comment(1)
Maq, thanks for your contribution. I suggest you reading previous answers before posting a new one.Jam
S
0

I had the dependency installed, but in my case I changed my tsconfig.app.json in order to get debugging in VSCode working. The change was replacing "include": ["src/**/*.d.ts"] with "include": ["src/**/.d.ts", "src/**/*.ts"]. I'm not sure why it would then suddenly be unable to find an installed dependency, but thought I'd still share it...

Soledadsolely answered 4/7, 2022 at 7:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.