Hessuew
Hessuew

Reputation: 783

Expo + [email protected]/9.0.0: @firebase/firestore:, Firestore (9.0.0): Could not reach Cloud Firestore backend

I just updated my Expo mobile application from [email protected] to [email protected] and came across following error: @firebase/firestore: Firestore (9.0.0): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds.

I'm running mobile app in Expo Go with android studio emulator. In application Auth works fine as I can log user in and out but when I try to do something with Firestore I get following error: Failed to get document because the client is offline.
This happens for example in basic getDoc() function

const dbRef = doc(db, 'exampleColletion', 'id');
    await getDoc(dbRef).then(document => {
      const information = document.data();
      if (information !== undefined) {
        eventsRetreived(information);
      }
    }).catch((err) => {
      eventsRetreived(err);
      console.log(err.message)
    })

I have made some test by using either [email protected] or [email protected] but in both I face the same problem but in [email protected] everything is working fine (and I'm not changing any code but changing only the version of firebase).

If more code or information is needed plz tell what I need to add and I will edit this post as needed.

EDIT
Found related github issue but even is closed I'm still facing the issue after testing [email protected]
https://github.com/firebase/firebase-js-sdk/issues/5402

EDIT2
Seems like issue is appearing in Expo v. 42. At the moment Expo support by default compat version of Firebase so the solution at the moment is to use [email protected] or compat version that is supported by Expo and is installed through expo install firebase

Upvotes: 1

Views: 579

Answers (1)

Max Fahl
Max Fahl

Reputation: 888

I can get it to work by using this setting:

initializeFirestore(firebaseInstance.current, {
  // @ts-ignore
  useFetchStreams: false,
  cacheSizeBytes: 100000000,
})

Seems iOS does not want to play nice with the Fetch API, using useFetchStreams falls back to using XMLHttpRequest instead, which seems to do the trick for me at the moment. I'm on firebase 9.0.2.

Upvotes: 1

Related Questions