Gabriel Donada
Gabriel Donada

Reputation: 449

firebase_compat_app__WEBPACK_IMPORTED_MODULE_0__.default.database is not a function

I'm getting the error below when trying to connect my app with Firebase: firebase_compat_app__WEBPACK_IMPORTED_MODULE_0__.default.database is not a function

I also did a test and I see that it happening only when connecting the database. If I comment on the database line, it works.

I also tried changing the rules on Firebase to true, and still not working. Note: I'm trying to use realtime database

Firebaseerror

Here is my code:

import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';


const firebaseConfig = {
    apiKey: process.env.REACT_APP_API_KEY ,
    authDomain: process.env.REACT_APP_AUTH_DOMAIN ,
    databaseURL: process.env.REACT_APP_DATABASE_URL,
    projectId: process.env.REACT_APP_PROJECT_ID,
    storageBucket: process.env.REACT_APP_STORAGE_BUCKET,
    messagingSenderId: process.env.REACT_APP_MESSAGING_SENDER_ID,
    appId: process.env.REACT_APP_APP_ID
  };

  firebase.initializeApp(firebaseConfig);

  const auth = firebase.auth();
  const database = firebase.database();

  export{ firebase, auth, database}

Upvotes: 2

Views: 1771

Answers (1)

Frank van Puffelen
Frank van Puffelen

Reputation: 598857

Firebase has two databases:

  • Firestore
  • Realtime Database

While they're both part of Firebase, they're completely separate.

You're importing firebase/compat/firestore, so Firestore. But then you call firebase.database(), which is the Realtime Database.

You'll need to pick one and stick with it:

  • If you want to use Firestore, keep your import as is and access it with firebase.firestore().
  • If you want to use Realtime Database, keep the call as is but import firebase/compat/database.

Upvotes: 3

Related Questions