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(); }
Advertisement
Answer
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';