Home > Software engineering >  TypeError: (0 , firebase_firestore__WEBPACK_IMPORTED_MODULE_1__.getFireStore) is not a function when
TypeError: (0 , firebase_firestore__WEBPACK_IMPORTED_MODULE_1__.getFireStore) is not a function when

Time:09-05

I'm following a tutorial on youtube and I came across a Server error while trying to set up firebase fireStore. The following error message occurs saying the getFireStore function is not a function:

Server Error
TypeError: (0 , firebase_firestore__WEBPACK_IMPORTED_MODULE_1__.getFireStore) is not a function

This error happened while generating the page. Any console logs will be displayed in the terminal window.
Source
firebase.js (20:23) @ eval

  18 | // Initialize Firebase
  19 | const app = !getApps().length ? initializeApp(firebaseConfig) : getApp(); //singleton pattern. if the number of apps initialised is null, initialise the app. else set app to getApp
> 20 | const db = getFireStore();
     |                       ^
  21 | const storage = getStorage();
  22 | 
  23 | export { app, db, storage };

Here is what my firebase.js file looks like:

// Import the functions you need from the SDKs you need
import { initializeApp, getApp, getApps } from "firebase/app";
import { getFireStore } from "firebase/firestore";
import { getStorage } from "firebase/storage";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries

// Your web app's Firebase configuration
const firebaseConfig = {
  apiKey: "###",
  authDomain: "###",
  projectId: "###",
  storageBucket: "###",
  messagingSenderId: "###",
  appId: "###"
};

// Initialize Firebase
const app = !getApps().length ? initializeApp(firebaseConfig) : getApp();
const db = getFireStore();
const storage = getStorage();

export { app, db, storage };

Does anyone know any solutions to this?

CodePudding user response:

Import statement has a capitalisation error.

It should be:

import { getFirestore } from "firebase/firestore";

and then initialised as:

const db = getFirestore();

Notice the s in firestore should not be capitalised.

CodePudding user response:

if you are going to use version 9 it is configured in this way, you can initialize the configuration You will have to import Cloud Firestore

    // Import the functions you need from the SDKs you need
    import { initializeApp } from "firebase/app";
    import { getFirestore } from "firebase/firestore";
    import { getAuth } from "firebase/auth";
    import { getStorage } from "firebase/storage";
    // TODO: Add SDKs for Firebase products that you want to use
    // https://firebase.google.com/docs/web/setup#available-libraries
    
    const firebaseConfigDevelopmet = {
      apiKey: "###",
      authDomain: "###",
      projectId: "###",
      storageBucket: "###",
      messagingSenderId: "###",
      appId: "###"
    };

Initialize Firebase

    const app = initializeApp(firebaseConfigDevelopmet);

get a referral to the service

    // getAuth
    const auth = getAuth(app);
    // getFirestore
    const db = getFirestore(app);
    // getStorage
    const storage = getStorage(app);
    
    export { auth, db, storage };
  • Related