angularfire2 cant find module 'firebase/app'
Solution 1
I'm gonna start with the big one, and I'd just say try deleting your node_modules
folder and package-lock.json
then re-run the command npm install
. On top of that just a few suggestions...
app.component (app.module?)
Your imports and files are inconsistent, I see you importing from angularfire2
as well as @angular/fire
. And while they're effectively the same thing, it's just that the Angular team is migrating/migrated to @angular/fire
. Run npm uninstall angularfire2
then npm i @angular/fire
. Finally you should update your app.component
(I think you mean app.module
) as so...
import { AngularFireModule } from '@angular/fire';
import { AngularFirestoreModule } from '@angular/fire/firestore';
import { RoomComponent } from './component/room/room.component';
import { AngularFireAuth } from '@angular/fire/auth';
import { FirebaseService } from "./service/firebase.service";
import { AngularFireAuthModule } from '@angular/fire/auth';
imports: [
BrowserModule,
AngularFireModule.initializeApp(firebaseconfig),
AngularFirestoreModule,
AngularFireAuthModule // IMPORT THE AUTH MODULE IF YOU'RE GOING TO USE IT
],
providers: [
FirebaseService,
{
provide: PERFECT_SCROLLBAR_CONFIG,
useValue: DEFAULT_PERFECT_SCROLLBAR_CONFIG
},
// AngularFireAuth (don't need/should not provide this, allow the module to set this up)
],
Mind you I'd love to be able to see more code, if you have a repo and would like for me to check that out I can provide additional help, but hopefully this'll be a solid start/fix.
Solution 2
npm install firebase
Solved my issue
Solution 3
Install firebase using this command npm i @angular/fire
Daniel Sanchez
Updated on June 09, 2022Comments
-
Daniel Sanchez about 2 years
app.component :
import { AngularFireModule } from '@angular/fire'; import { AngularFirestoreModule } from 'angularfire2/firestore'; import { RoomComponent } from './component/room/room.component'; import { AngularFireAuth } from '@angular/fire/auth'; import { FirebaseService } from "./service/firebase.service"; import { AngularFireAuthModule } from 'angularfire2/auth'; imports: [ BrowserModule, AngularFireModule.initializeApp(firebaseconfig), AngularFirestoreModule ], providers: [ FirebaseService, { provide: PERFECT_SCROLLBAR_CONFIG, useValue: DEFAULT_PERFECT_SCROLLBAR_CONFIG }, AngularFireAuth ],
package.json file :
{ "dependencies": { "@angular/animations": "^5.2.11", "@angular/cdk": "^5.2.4", "@angular/common": "^5.2.0", "@angular/compiler": "^5.2.0", "@angular/core": "^5.2.0", "@angular/forms": "^5.2.0", "@angular/http": "^5.2.0", "@angular/material": "^5.2.4", "@angular/platform-browser": "^5.2.0", "@angular/platform-browser-dynamic": "^5.2.0", "@angular/router": "^5.2.0", "angularfire2": "^5.0.1", "core-js": "^2.4.1", "dateformat": "^3.0.3", "firebase": "^5.5.1", "rxjs": "^6.3.2", "rxjs-compat": "^6.3.2", "zone.js": "^0.8.19" }, "devDependencies": { "@angular/cli": "~1.7.4", "@angular/compiler-cli": "^5.2.0", "@angular/language-service": "^5.2.0", "ts-node": "~4.1.0", "tslint": "~5.9.1", "typescript": "~2.5.3" } }
The imports that doesnt work located in a service:
import { AngularFirestore, AngularFirestoreCollection, AngularFirestoreDocument } from 'angularfire2/firestore'; import { AngularFireAuth } from '@angular/fire/auth'; import { auth } from 'firebase/app' import { Observable } from 'rxjs';
I only included the dependencies that may have something to do with the error but if i missed something please tell me.
I've already tried multiple versions. This does work but it has an error. The problem lies within the import { auth } which allows me to login to firebase. I dont know what the problem is. Sometimes it compiles, sometimes it doesn't. This is the only version combination I used so far that compile sometimes even with error. Other versions just breaks other imports.
The project only compiles if i remove the auth import momentarily and then put it back in then save it.
-
Jigno Alfred Venezuela almost 6 yearsMake sure it's the app.module.ts not app.component.ts. What error are you getting?
-
Daniel Sanchez almost 6 yearssrc/app/service/firebase.service.ts(4,22): error TS2307: Cannot find module 'firebase/app'. It's working correctly, it just has this error I dont know why
-
Daniel Sanchez almost 6 yearsThanks! I fixed it already and I did some of what you said. I updated those imports but it still didn't work . Fixed it by changing firebase/app into just firebase. I think it was changed in later versions and my import is old.