【问题标题】:Persistence support for Firestore in Expo React Native appExpo React Native 应用程序中对 Firestore 的持久性支持
【发布时间】:2021-04-23 18:23:20
【问题描述】:
我收到以下错误:
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.
我正在使用以下导入
import "expo-firestore-offline-persistence";
import firebase from "firebase";
import "firebase/firestore";
由于 Expo 托管工作流不支持持久性,我正在使用我找到的 expo-firestore-offline-persistence 包。
如何获得 Firestore 的 non-memory-only 版本?
【问题讨论】:
标签:
firebase
react-native
google-cloud-firestore
expo
【解决方案1】:
仅内存 Firestore 已添加到 Version 7.13.0:2020 年 3 月 26 日:
添加了仅内存的 Firestore 构建。它不是将数据保存在 IndexedDB 中,而是将其保存在内存中。此构建比全功能构建小约 14%,因为它没有与 IndexedDB 相关的代码。如果您不关心跨会话持久化数据,或者您的代码在不支持 IndexedDB 的环境中运行,请使用此构建来减小应用程序大小。它在特殊的导入路径下可用。你可以这样导入:
import * as firebase from 'firebase/app';
import 'firebase/firestore/memory';
// Don't change the format for any other products.
import 'firebase/auth';
// etc.
或者如果使用 CDN:
<script src="https://www.gstatic.com/firebasejs/7.13.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/7.13.0/firebase-firestore.memory.js"></script>
<!-- Don't change the format for any other products. -->
<script src="https://www.gstatic.com/firebasejs/7.13.0/firebase-auth.js"></script>
<!-- etc. -->