如何解决"Error: Failed to initialize Google Cloud Firestore client with the available credentials."?



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

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. 解决方案

更新

您只需通过执行npm i firebase-admin来更新您的 Firebase 管理员。感谢@samthecodingman提供的信息。

以前

解决此问题的一种方法是通过执行以下命令降级Firebase管理员的版本npm i firebase-admin@8.9.0因为它似乎只影响版本8.9.1


2. 解决方案

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

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

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

最新更新