首页 > 解决方案 > Expo React Native 应用程序中对 Firestore 的持久性支持

问题描述

我收到以下错误:

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的是我找到的包。

如何获得non-memory-onlyFirestore 的构建版本?

标签: firebasereact-nativegoogle-cloud-firestoreexpo

解决方案


仅内存 Firestore 已在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. -->

推荐阅读