I searched for several hours to implement firestore offline persistence because its crucial for my app to work. I handle multiple chats inside my app and its a fatal error to download data every time again.
This is my code sample, its the root App.js file which is the first one beeing called:
....
//imports related to firebase
import * as firebase from "firebase";
import ApiKeys from "./constants/ApiKeys";
export default function App() {
//firebase project initialisation
if (!firebase.apps.length) {
firebase.initializeApp(ApiKeys);
var db = firebase.firestore();
db.settings({ experimentalForceLongPolling: true });
console.log("DB INITIALISED");
db.enablePersistence() //HERE IS THE PROBLEM
.catch((err) => {
if (err.code == 'failed-precondition') {
// Multiple tabs open, persistence can only be enabled
// in one tab at a a time.
// ...
} else if (err.code == 'unimplemented') {
// The current browser does not support all of the
// features required to enable persistence
// ...
}
})
};.....
The API Keys look like this:
const firebaseConfig = {
apiKey: "***",
authDomain: "***",
databaseURL: "https://***",
projectId: "***",
storageBucket: "***",
messagingSenderId: "***",
appId: "***",
measurementId: "***"
};
export default firebaseConfig;
I receive the following error which I can not work around: FirebaseError: You are using the memory-only build of Firestore. Persistence support is only available via the @firebase/firestore bundle or the firebase-firestore.js build.
I have installed the complete "firebase" bundle and also access to @firebase/firestore, I checked this already, and I implemented it same as in the official docs. Everything works but when I want to enable the persistence... It crashes with the error mentioned above.
What can I do now? Do I miss another package, have I done something wrong?
As a sidenote, authentification persistence works perfectly inside my app, just the firestore persistence is failing.
Currently using firebase SDK 8.2.3
from firebase firestore offline persistence FirebaseError
No comments:
Post a Comment