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

前端 未结 21 1500
独厮守ぢ
独厮守ぢ 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:18

    Enabling Firestore for Nativescript

    During plugin installation you'll be asked whether or not you use Firestore.

    In case you're upgrading and you have the firebase.nativescript.json file in your project root, edit it and add: "firestore": true. Then run rm -rf platforms && rm -rf node_modules && npm i.

    init / initializeApp

    By default Firestore on iOS and Android persists data locally for offline usage (web doesn't by default, and the regular Firebase DB doesn't either on any platform). If you don't like that awesome feature, you can pass persist: false to the init function.

    Note that initializeApp is simply an alias for init to make the plugin compatible with the web API.

    const firebase = require("nativescript-plugin-firebase/app");
    
    firebase.initializeApp({
      persist: false
    });
    

    collection

    A 'collection' is at the root of any Firestore interaction. Data is stored as a 'document' inside a collection.

     const citiesCollection = firebase.firestore().collection("cities");
    

    Source: nativescript-plugin-firebase

提交回复
热议问题