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 issueUsing 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:
- Created 4 years ago
- Reactions:10
- Comments:10 (3 by maintainers)
temp fix:
npm i firebase-admin@8.9.0
issue only seems to affect 8.9.1
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