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 > [email protected]
Am i doing wrong?
That's because the firebase core library does not include the firestore library. import firebase from 'firebase/app'; import 'firebase/firestore'; Breaks on Android if you are using React Native. Seems to be fine on iOS :-/ This works perfectly as of February 2019. Thank you!! :) Thank you! The second import statement was what I was missing.
this is an example of the most basic firestore setup for a react application. create-react-app installed. understanding of react and javascript. basic understanding of npm and firebase. the first thing we need to do is set up our firebase app inside the firebase console.
choose a location. Ideally where your users are likely to be and not necessarily where you are. start by making a new react app from the command-line. once installed, make a new folder called firebase inside the src folder. you can make the file at the same time too!
In case you're upgrading and you have the firebase.nativescript.json file in your project root, edit it and add: "firestore": true. Then run rm -rf platforms && rm -rf node_modules && npm i.
If you're using the official firebase npm package, this is how you import it.
import firebase from 'firebase';
import 'firebase/firestore';
ES6:
import '@firebase/firestore'
reference: https://www.npmjs.com/package/@firebase/firestore
I have resolved this issue by using require('firebase/firestore')
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:
import * as firebase from 'firebase';
import 'firebase/firestore';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With