skip to Main Content

I’m trying to import Angular firebase into a project
import * as firebase from "firebase"
falls into error
Cannot find module 'firebase' or its corresponding type declarations .ts(2307)
and I ran the command to install @angular/firebase:
npm I firebase @angular/fire --save

what I can do?

2

Answers


  1. Chosen as BEST ANSWER

    you can write import * as firebase from 'firebase/compat'; adn this work good


  2. As stated here after the configuration on Firebase Cloud you need:

    ng add @angular/fire
    

    In your app module:

    import { environment } from 'src/environments/environment';
    import { AngularFireModule } from '@angular/fire';
    import { AngularFirestoreModule } from '@angular/fire/firestore';
    
    @NgModule({
      declarations: [AppComponent, TaskDialogComponent, TaskComponent],
      imports: [
        ...
        AngularFireModule.initializeApp(environment.firebase),
        AngularFirestoreModule
      ],
      providers: [],
      bootstrap: [AppComponent],
    })
    export class AppModule {}
    

    In your component:

    ...
    
    @Component({...})
    export class AppComponent {
      todo = this.store.collection('todo').valueChanges({ idField: 'id' }) as Observable<Task[]>;
      inProgress = this.store.collection('inProgress').valueChanges({ idField: 'id' }) as Observable<Task[]>;
      done = this.store.collection('done').valueChanges({ idField: 'id' }) as Observable<Task[]>;
      ...
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search