0

i was trying to import my firebase project to expo, but got the error "firebase.js:15 Uncaught TypeError: Cannot read properties of undefined (reading 'firestore')". I have my firestore app like this:

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

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

initializeApp(firebaseConfig);

const db = firebase.firestore();

export { db };

Also import the initializeapp from firebase, otherwise the error is "firebase.js:13 Uncaught TypeError: Cannot read properties of undefined (reading 'initializeApp')"

The version of firebase I'm using is "firebase": "^9.8.1",

1 Answer 1

3

For me when I used Expo I found I had to use the path:

firebase/compat/app

firebase/compat/firestore

instead, so like this;

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

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

const app = firebase.initializeApp(firebaseConfig);

export const db = app.firestore();

Also I'd recommend the slightly different way of declaring it as shown above, declaring the app constant because it's just nicer in case you need to add more exports such as:

const app = firebase.initializeApp(firebaseConfig);

export const auth = app.auth();
export const db = app.firestore();
export const storage = app.storage();

Give it a try and see if it works

2
  • 1
    Thank you very much for the help, regarding the answer I had to install version 9.6.11 of Firebase and with the help you offered me, the program works correctly
    – YCrhis
    May 25, 2022 at 2:30
  • How did you properly downgrade firebase-tools ?
    – isa
    Sep 4, 2022 at 5:48

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.