When I try to initialize Firebase Cloud Firestore, I ran into the following error:
Uncaught TypeError: WEBPACK_IMPORTED_MODULE_0_firebase.firestore is not a function
I installed firebase with npm install firebase --save
previously.
import * as firebase from 'firebase'; import router from '../router'; const config = { apiKey: "a", authDomain: "a", databaseURL: "a", projectId: "a", storageBucket: "a", messagingSenderId: "a" }; if(!firebase.apps.length){ firebase.initializeApp(config); let firestore = firebase.firestore(); }
Cloud Firestore is a NoSQL document database that lets you easily store, sync, and query data for your mobile and web apps - at global scale.
To use the Firestore mobile/web client libraries and other Firebase features, add Firebase to your existing Google project. Add Firebase to your existing Google Cloud project: Log in to the Firebase console, then click Add project. Select your existing Google Cloud project from the dropdown menu, then click Continue.
I fixed it by importing multiple libraries: firebase
and firebase/firestore
. That's because the firebase
core library does not include the firestore library.
import firebase from 'firebase/app'; import 'firebase/firestore';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With