question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

Using the new version 8.9.1 of firebase-admin, firebase-functions deployments using NodeJS 10 with the Firebase CLI fail. Reverting firebase-admin to version 8.9.0 resolves the issue.

Here is the command used to deploy functions:

$ firebase deploy --only functions

=== Deploying to ‘ipregistry-dashboard-dev’…

i deploying functions Running command: yarn --cwd functions run clean yarn run v1.21.1 $ rm -rf dist/ Done in 0.04s. Running command: yarn --cwd functions run lint yarn run v1.21.1 $ tslint -p tsconfig.json Done in 2.03s. Running command: yarn --cwd functions run build yarn run v1.21.1 $ yarn run lint && ./node_modules/.bin/tsc $ tslint -p tsconfig.json Done in 4.63s. Running command: cp -r $RESOURCE_DIR/keyfiles $RESOURCE_DIR/dist ✔ functions: Finished running predeploy script. i functions: ensuring necessary APIs are enabled… ✔ functions: all necessary APIs are enabled i functions: preparing functions directory for uploading…

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] (/home/X/functions/node_modules/firebase-admin/lib/utils/error.js:42:28) at new FirebaseFirestoreError (/home/X/functions/node_modules/firebase-admin/lib/utils/error.js:220:23) at getFirestoreOptions (/home/X/functions/node_modules/firebase-admin/lib/firestore/firestore.js:96:11) at initFirestore (/home/X/functions/node_modules/firebase-admin/lib/firestore/firestore.js:105:19) at new FirestoreService (/home/X/functions/node_modules/firebase-admin/lib/firestore/firestore.js:43:32) at /home/X/functions/node_modules/firebase-admin/lib/firebase-app.js:261:20 at FirebaseApp.ensureService_ (/home/X/functions/node_modules/firebase-admin/lib/firebase-app.js:351:23) at FirebaseApp.firestore (/home/X/functions/node_modules/firebase-admin/lib/firebase-app.js:259:28) at Object.<anonymous> (/home/X/functions/dist/callables/account-activate.js:10:33) at Module._compile (internal/modules/cjs/loader.js:776:30)

The line 10 from account-active.js is const firestoreDatabase = admin.firestore();.

Firebase admin initialization is made as follows:

import {FirebaseAdminHelper} from '../helpers/firebase-admin-helper';
const admin = FirebaseAdminHelper.initializeApp();
const auth = admin.auth();
const config = functions.config();
const firestoreDatabase = admin.firestore();

where FirebaseAdminHelper is defined as follows:

import * as admin from 'firebase-admin';

export class FirebaseAdminHelper {

    static initializeApp(): admin.app.App {
        try {
            return admin.initializeApp();
        } catch (error) {
            // Ignore "already initialized" errors.
            // This case should only happen locally while deploying, not on real environments.
            return admin.app();
        }
    }

}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:10
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

25reactions
darinwcommented, Jan 16, 2020

temp fix:

npm i firebase-admin@8.9.0

issue only seems to affect 8.9.1

2reactions
npomfretcommented, Jan 17, 2020

Same problem here using :

admin.initializeApp({ credential: admin.credential.applicationDefault() });

Downgrading using yarn add firebase-admin@8.9.0 seems to get it working again.

Thanks @darinw

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to solve "Error: Failed to initialize Google Cloud Firestore ...
The Google Application Credentials can you get by following these steps: Open the Service Accounts pane of the Google Cloud Console.
Read more >
Add the Firebase Admin SDK to your server - Google
Once you have created a Firebase project, you can initialize the SDK with an authorization strategy that combines your service account file together...
Read more >
Initializing the gcloud CLI | Google Cloud CLI Documentation
gcloud init performs the following setup steps: Authorizes the gcloud CLI to use your user account credentials to access Google Cloud, or lets...
Read more >
Spring Framework on Google Cloud
Configure Spring JDBC with a few properties to use Google Cloud SQL ... Credentials provided by the Google Cloud SDK gcloud auth application-default...
Read more >
Using Firebase - Expo Documentation
A guide on getting started and using Firebase JS SDK and React Native Firebase library.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found