TypeError: Cannot read property 'length' of undefined in react-native

Viewed 1347

I am implementing firebase login/signup in my react-native app. In the android emulator mode, I am being successfully logged in (keeping few warnings aside). But when I closed emulator and switched app to web mode; I started getting these errors:

enter image description here

Here is the firebase.js code :-

import * as firebase from "firebase";
import "firebase/firestore";
import "firebase/auth";

const firebaseConfig = {
  apiKey: "...",
  authDomain: "...",
  projectId: "...",
  storageBucket: "...",
  messagingSenderId: "...",
  appId: "...",
  measurementId: "...",
};

let app;

if (firebase.apps.length === 0) {
    app = firebase.initializeApp(firebaseConfig);
} else {
    app = firebase.app();
}

const db = app.firestore();
const auth = firebase.auth();

export { db, auth };

Thank you!

1 Answers

Try changing your first line of code to

import firebase from 'firebase';

This approach worked for me

Related