firebase.firestore() is not a function when trying to initialize Cloud Firestore

前端 未结 21 1336
独厮守ぢ
独厮守ぢ 2020-12-01 02:45

When I try to initialize Firebase Cloud Firestore, I ran into the following error:

Uncaught TypeError: WEBPACK_IMPORTED_MODULE_0_firebase

相关标签:
21条回答
  • 2020-12-01 03:01

    If by any chance, your code is under witchcraft, and import firebase/firestore won't work, then include it directly:

    import '@firebase/firestore/dist/esm/index';
    

    If it's not there, then:

    npm install @firebase/firestore
    
    0 讨论(0)
  • 2020-12-01 03:01

    If you are updating from an earlier version of firebase and you are pulling your hair out about this issue, try const Firebase = require('firebase/firebase') instead of require('firebase/app')

    0 讨论(0)
  • 2020-12-01 03:02

    Solution for Angular 8 (as of 4th January 2020):

    1. Delete package-lock.json file
    2. Run npm install
    3. import AngularFirestoreModule from @angular/fire/firestore

    Just need to import AngularFirestoreModule.

    // App.module.ts
    
    import { AngularFireModule } from '@angular/fire';
    import { AngularFirestore, AngularFirestoreModule } from '@angular/fire/firestore';
    import { AngularFireDatabaseModule } from '@angular/fire/database';
    imports: [
        AngularFireModule.initializeApp(environment.firebaseConfig),
        AngularFirestoreModule,
        AngularFireDatabaseModule
    ]
    
    0 讨论(0)
  • 2020-12-01 03:03

    I think I've got it for folks using electron-webpack. Solution was from a post related to importing codemirror. https://github.com/electron-userland/electron-webpack/issues/81

    This worked for me.

    // package.json
    {
      //...
      "electronWebpack": {
        "whiteListedModules": [
          "firebase"
        ]   
      },
      //...
    }
    
    0 讨论(0)
  • 2020-12-01 03:03

    I used to have the same problem, it was a bug. I was importing firestore from firebase (it was done automatically by the IDE...) when i should imported it from the .js file where i initialized firebase app.

    0 讨论(0)
  • 2020-12-01 03:05

    Removing node_modules directory together with package-lock.json and then running npm install fixed it for me.

    https://github.com/angular/angularfire2/issues/1880

    0 讨论(0)
提交回复
热议问题