如何解决“错误:无法使用可用的凭据初始化Google Cloud Firestore客户端”?

康斯坦丁啤酒

当尝试使用部署Firebase Cloud Functions时,Firebase deploy出现以下错误:

Error: Error occurred while parsing your function triggers.

Error: Failed to initialize Google Cloud Firestore client with the available credentials. Must initialize the SDK with a certificate credential or application default credentials to use Cloud Firestore API.
    at FirebaseFirestoreError.FirebaseError [as constructor] (/functions/node_modules/firebase-admin/lib/utils/error.js:42:28)
    at new FirebaseFirestoreError (/functions/node_modules/firebase-admin/lib/utils/error.js:220:23)
    at getFirestoreOptions (/functions/node_modules/firebase-admin/lib/firestore/firestore.js:96:11)
    at initFirestore (/functions/node_modules/firebase-admin/lib/firestore/firestore.js:105:19)
    at new FirestoreService (/functions/node_modules/firebase-admin/lib/firestore/firestore.js:43:32)
    at /functions/node_modules/firebase-admin/lib/firebase-app.js:261:20
    at FirebaseApp.ensureService_ (/functions/node_modules/firebase-admin/lib/firebase-app.js:351:23)
    at FirebaseApp.firestore (/functions/node_modules/firebase-admin/lib/firebase-app.js:259:28)
    at FirebaseNamespace.fn (/functions/node_modules/firebase-admin/lib/firebase-namespace.js:327:45)
    at Object.<anonymous> (/functions/lib/users.js:6:27)

如何避免这种情况?

康斯坦丁啤酒

1.解决方案

更新

您只需执行即可更新Firebase Admin npm i firebase-admin感谢@samthecodingman提供的信息。

以前

解决此问题的一种方法是通过执行Firebase Adminnpm i [email protected]似乎仅影响版本的原因来降级其版本8.9.1


2.解决方案

解决该问题的另一种方法是export GOOGLE_APPLICATION_CREDENTIALS="path/to/key.json"在命令行中运行您可以按照以下步骤获取Google应用程序凭据:

  1. 打开Google Cloud Console的“服务帐户”窗格
  2. 确保选择了App Engine默认服务帐户,然后使用右侧的选项菜单选择创建密钥。
  3. 出现提示时,选择JSON作为密钥类型,然后单击“创建”。

有关更多信息,请参阅Firebase文档。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何使用服务帐户凭据初始化Google Cloud Storage NodeJS客户端库

Google Cloud Storage客户端

gRPC / proto Google Cloud客户端库与GAPIC Google Cloud客户端库

Cloud Foundry UAA服务器的客户端凭据

Firebase Cloud Firestore抛出“客户端脱机”

如何使用 API Gateway 传递给 Cloud Function 的服务帐户的 JWT 在 Cloud Function 中初始化 Google BigQuery 客户端

Cloud Storage python客户端无法检索存储桶

Spring Cloud Config客户端无法找到PropertySource

Google Cloud Endpoints非WebApp iOS客户端Blobstore

Google Cloud 存储:授予 OAuth 2.0 客户端权限

Google Cloud Storage节点客户端ResumableUploadError

Google Cloud Functions与客户端的实时通信

Google Cloud Vision是否保存客户端的输入数据?

用于 Stackdriver Trace 的 Google Cloud Java 客户端

如何微调Spring Cloud Feign客户端?

使用 terraform 从 Cloud SQL 检索客户端证书

Google Cloud pubsub node.js客户端与Google Cloud功能不兼容

无法使用客户端mysql CL工具连接到Google Cloud SQL实例

无法获取客户端数据以显示 [firestore]

在 Apache Beam 中导入 Google Firestore Python 客户端

客户端与客户端与Cloud Endpoints的通信

Firestore规则使用Flutter客户端验证时间戳

使用 Firestore 触发器更新客户端状态

如何使用客户端库将格式传递给Google Cloud Translation API?

如何使用Google Cloud客户端库进行基于API密钥的REST调用

如何使用来自Node.JS客户端的容器映像启动Google Cloud实例?

Google Cloud OAuth授权错误:此客户端仅限于其组织内的用户

Google Cloud Endpoints Android客户端-身份验证错误

如何将客户端Firebase云消息传递令牌转换为Google Cloud函数?