1

I just updated my Expo mobile application from firebase@9.0.0-beta.7 to firebase@9.0.1 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 firebase@9.0.1 or firebase@9.0.0 but in both I face the same problem but in firebase@9.0.0-beta.7 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 firebase@9.0.2
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 firebase@9.0.0-beta.7 or compat version that is supported by Expo and is installed through expo install firebase

Hessuew
  • 583
  • 1
  • 4
  • 23
  • Did you try using [Node.js SDK](https://www.npmjs.com/package/firebase-admin)? Do you still get these errors there? – Farid Shumbar Sep 09 '21 at 09:52
  • @FaridShumbar I have another Expo project that contains Firebase functions that uses Firebase Admin Node.js SDK and it works fine. Also that project uses `firebase@9.0.1` and it has no problem when Firestore is called. – Hessuew Sep 09 '21 at 10:31
  • BUT.. that project uses expo-web and is using `firebase@9.01` in web enviroment (but setting the config in same way still as in mobile project). I don't know if this affects things at all but just mentioning. – Hessuew Sep 09 '21 at 11:15
  • I'm facing the same issue while using Expo v. 42. – Max Fahl Oct 05 '21 at 07:11
  • @MaxFahl interesting. We probably need to wait until expo v. 43 is released where modular firebase could be used and at while waiting either use ´firebase@9.0.0-beta.7´ or compat version that comes by `expo install firebase` – Hessuew Oct 05 '21 at 09:50
  • Yes. I'm going with "9.0.0-beta.7" for now, since I'm mostly using it for a hobby project of mine. Thanks for pointing that version out. – Max Fahl Oct 05 '21 at 12:43
  • Having the same issue on expo 43 beta, even though the tell you to use firebase 9. – Max Fahl Oct 14 '21 at 11:24
  • @MaxFahl Did you use `firebase@9.0.2` that is installed when running `expo upgrade` and is told to be used in Expo v43 beta documentation: > Recommended firebase version is now 9.0.2. – Hessuew Oct 15 '21 at 05:25

1 Answers1

1

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.

Max Fahl
  • 818
  • 9
  • 19