Home > Net >  React Native import firebase auth and firestore
React Native import firebase auth and firestore

Time:02-16

I'm getting errors when I try to simply load the auth and firestore from firebase.

Error message: TypeError: (0, _app.initializeApp) is not a function. (In '(0, _app.initializeApp)(firebaseConfig)', '(0, _app.initializeApp)' is undefined)

import { initializeApp } from "firebase/app";
import { getFirestore } from "firebase/firestore";


const firebaseConfig = {
  apiKey: "KEY",
  authDomain: "app.firebaseapp.com",
  projectId: "app",
  storageBucket: "app.appspot.com",
  messagingSenderId: "1293821378",
  appId: "5647"
};

const app = initializeApp(firebaseConfig);
const db = getFirestore(app);
const auth = app.auth();

export { db, auth } 

Also when I try to import the auth from another file I try this:

import { auth } from '../firebase';

CodePudding user response:

If you are using Firebase version <9.0.0 which only supports name-spaced SDK, then use the older imports only and not the modular syntax. Try refactoring the code as shown below:

import firebase from "firebase/app";
import "firebase/firestore";
import "firebase/auth"

const firebaseConfig = {};

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

export { db, auth } 

Also makes sure you are referring to Web (name-spaced) tab in the documentation.

  • Related