Reputation: 449
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
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
Reputation: 598857
Firebase has two databases:
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:
firebase.firestore()
.firebase/compat/database
.Upvotes: 3