firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.86k stars 891 forks source link

Importing from 'firebase/firestore' imports the memory-only build instead of the normal build in React Native #5156

Closed swittk closed 3 years ago

swittk commented 3 years ago

[REQUIRED] Describe your environment

[REQUIRED] Describe the problem

We have been using a custom IndexedDB implementation in our React native app (over 1 year), and it has worked with Firestore reliably, providing offline persistence (a similar hack is via expo-firestore-offline-persistence npm package). However, with Firestore version 8.1.2 we found that importing 'firebase/firestore' results in the memory-only build being loaded, which throws an error immediately when we try to enable persistence.

Firebase documentation for release 7.13.0, which contained the first release for the memory-only build, explicity says that "It is available under a special import path" of 'firebase/firestore/memory'. However, ever since firestore version around 2.1.0, that path also doesn't exist (the build folder at dist/memory/rn does not exist). We believe this is due to some error in the packaging process for the firestore build, and so decided to post this issue here.

Steps to reproduce:

  1. Make the React native environment have a functioning IndexedDB implementation
    • npm install expo-sqlite indexeddbshim expo-firestore-offline-persistence
  2. Import Firebase in code
  3. Try to enable offline persistence. This would fail for "firebase" package version above 8.1.1 due to the firestore build defaulting to the memory-only build for react native.

Relevant Code:

(React-Native Expo)

import 'expo-firestore-offline-persistence'
import 'firebase/firestore';

import firebase from 'firebase';

firebase.initializeApp(...config)

const firestore = firebase.firestore();
firestore
  .enablePersistence()
  .then(() => {
    // Initialize Cloud Firestore through firebase
    firebase.firestore();
    console.log('Successfully enabled offline persistence');
  })
swittk commented 3 years ago

Closing due to it already being fixed with Firebase release 8.2.7