Constantin Beer
Constantin Beer

Reputation: 5835

How to solve "Error: Failed to initialize Google Cloud Firestore client with the available credentials."?

When trying to deploy my Firebase Cloud Functions with Firebase deploy I get the following error:

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)

How can I avoid this?

Upvotes: 0

Views: 1648

Answers (1)

Constantin Beer
Constantin Beer

Reputation: 5835

1. Solution

UPDATE

You can simply update your Firebase Admin by executing npm i firebase-admin. Thanks to @samthecodingman for the information.

PREVIOUS

One way to solve this problem is to downgrade the version of your Firebase Admin by executing npm i [email protected] cause it seems to only affect version 8.9.1.


2. Solution

Another way to solve the problem is to run export GOOGLE_APPLICATION_CREDENTIALS="path/to/key.json" in the command line. The Google Application Credentials can you get by following these steps:

  1. Open the Service Accounts pane of the Google Cloud Console.
  2. Make sure that App Engine default service account is selected, and use the options menu at right to select Create key.
  3. When prompted, select JSON for the key type, and click Create.

For more information see the Firebase docs

Upvotes: 2

Related Questions