Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

firebase2.default.firestore is not a function - React Firebase

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?

like image 799
Noman Ali Avatar asked Oct 12 '17 11:10

Noman Ali


People also ask

Why can't I use firebase with FireStore?

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.

What is the basic FireStore setup for a react application?

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.

How do I add firebase to react app?

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!

How to add FireStore in NativeScript?

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.


4 Answers

If you're using the official firebase npm package, this is how you import it.

import firebase from 'firebase';
import 'firebase/firestore';
like image 185
CLUTCHER Avatar answered Sep 22 '22 08:09

CLUTCHER


ES6:

import '@firebase/firestore'

reference: https://www.npmjs.com/package/@firebase/firestore

like image 44
Henry Avatar answered Sep 20 '22 08:09

Henry


I have resolved this issue by using require('firebase/firestore')

like image 34
Noman Ali Avatar answered Sep 20 '22 08:09

Noman Ali


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';
like image 39
muhyidin Avatar answered Sep 23 '22 08:09

muhyidin