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

前端 未结 21 1494
独厮守ぢ
独厮守ぢ 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条回答
  •  Happy的楠姐
    2020-12-01 03:17

    If you're like me and like everything typed on typescript (it's the purpose, by the way), you can try:

    import * as firebase from "nativescript-plugin-firebase";
    import { User, firestore } from "nativescript-plugin-firebase";
    
    import * as firebaseapp from "nativescript-plugin-firebase/app";
    

    So you can do stuff like that:

    firebase.getCurrentUser().then((user: User) => { /* something */ });
    
    const mycollection : firestore.CollectionReference = firebaseapp.firestore().collection("mycollection");
    

提交回复
热议问题