Possible Unhandled Promise Rejection (id: 20): TypeError: _util.base64.tI is not a function. React Native

Viewed 355

I am building an app using react native, I use firebase as my database. Everything was working fine. I started running the app on my device through Xcode. It worked but now I get this warning on my device and simulator which prevents me from getting data from firebase database. the warning is

"Possible Unhandled Promise Rejection (id: 20): TypeError: _util.base64.tI is not a function. (In '_util.base64.tI(t, !1)', '_util.base64.tI' is undefined)"

I don't know where did this (_util.base64) come from. I guess the problem has to do with this code part (the promise) as when I remove this part it works fine but unable to get data without it. can anyone help?

useEffect(() => {
    db.collection("Appointments")
      .orderBy("Timing", "desc")
      .limit(2)
      .get()
      .then((querySnapshot) => {
        const list = [];
        querySnapshot.forEach((doc) => {
          const { Speciality, Date, TimeSlot } = doc.data();
          list.push({
            id: doc.id,
            Speciality,
            Date,
            TimeSlot,
          });
        });

        setAppointments(list);
      })
      .catch((error) => {
        alert(error.message);
        console.log(error);
      });
  }, []);

This is the warning that shows up

Those are my dependencies

1 Answers

What I did to solve it was:

run expo install firebase

Create a config.js file where I put my Firebase credentials:

import * as firebase from 'firebase';

// Initialize Firebase
var firebaseConfig = {
  //Your Firebase credentials
};

var app = firebase.initializeApp(firebaseConfig);

export const db = app;

And import that file wherever I need it

import { db } from '../config';
//Here's where I call firestore (You can also do this in the config file)
import 'firebase/firestore';

db.firestore().
collection('your_collection').get().then(
    //The stuff you want to do
);

At least, now it works for me.

In this link you can see the oficial expo with firebase documentation

Related