I am trying to use firestore in my reactjs app.
When i call firestore from firebase config object.
It says
firebase2.default.firestore is not a function
Here is the code
import firebase from 'firebase'
const config = {
apiKey: "AIzaSxxxxxxqpUeqKXI",
authDomain: "payxxxxxa1.firebaseapp.com",
databaseURL: "https://payxxxxxxxa1.firebaseio.com",
projectId: "payxxxxxxja1",
storageBucket: "payxxxxxa1.appspot.com",
messagingSenderId: "281xxxxxxxx576"
}
firebase.initializeApp(config)
export const fire = firebase
export const ref = firebase.database().ref()
export const firebaseAuth = firebase.auth
export const messaging = firebase.messaging();
export const db = firebase.firestore();
Firebase version is 4.5.0
npm list firebase > firebase@4.5.0
Am i doing wrong?
I fixed it by importing multiple libraries: firebase and firebase/firestore. That's because the firebase core library does not include the firestore library innately. So the full code to fix it is:
ES6:
import '@firebase/firestore'
reference: https://www.npmjs.com/package/@firebase/firestore
I have resolved this issue by using
require('firebase/firestore')
If you're using the official firebase npm package, this is how you import it.