无法导入 Firestore fieldValue(existsSync 不是函数)

cannot import Firestore fieldValue (existsSync is not a function)

我需要在我的 React 应用程序中删除 Firestore 文档中的字段,Firebase documentation 提到我应该使用 'firebase-admin':

中的 FieldValue
// Get the `FieldValue` object
var FieldValue = require("firebase-admin").firestore.FieldValue;

但是当我尝试像这样获取 FieldValue 对象时,出现错误:

TypeError: existsSync is not a function

./node_modules/grpc/node_modules/node-pre-gyp/lib/pre-binding.js/exports.find

我还在我的控制台中看到了一些警告:

./node_modules/grpc/node_modules/node-pre-gyp/lib/util/versioning.js 16:20-67 Critical dependency: the request of a dependency is an expression

./node_modules/google-gax/node_modules/grpc/node_modules/node-pre-gyp/lib/util/versioning.js 16:20-67 Critical dependency: the request of a dependency is an expression

./node_modules/grpc/node_modules/node-pre-gyp/lib/pre-binding.js 19:22-48 Critical dependency: the request of a dependency is an expression

./node_modules/google-gax/node_modules/grpc/node_modules/node-pre-gyp/lib/pre-binding.js 19:22-48 Critical dependency: the request of a dependency is an expression

./node_modules/google-gax/node_modules/grpc/src/grpc_extension.js 30:14-35 Critical dependency: the request of a dependency is an expression

这可能是什么问题?

firebase-admin 节点模块用于服务器端节点进程。您正在尝试在客户端 React 应用程序中使用它,但这是行不通的。

在客户端 React 中,您应该使用常规的 Firebase JavaScript/Web SDK 并使用来自 that tab in the docs:

的代码片段
var cityRef = db.collection('cities').doc('BJ');

// Remove the 'capital' field from the document
var removeCapital = cityRef.update({
    capital: firebase.firestore.FieldValue.delete()
});