Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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(); } 
like image 470
Eyk Rehbein Avatar asked Oct 08 '17 21:10

Eyk Rehbein


People also ask

What does firebase firestore () do?

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.

How do I enable firestore project?

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.


1 Answers

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'; 
like image 121
Eyk Rehbein Avatar answered Oct 13 '22 12:10

Eyk Rehbein