Sumit Jangra
Sumit Jangra

Reputation: 147

I am getting error while deploying google cloud functions. Error - 'Invalid contents in the credentials file'

I am getting error while deploying google cloud function - with firebase (earlier it was working fine but suddenly this error started coming so I deleted the whole folder and did the process again but still not resolved)

index.js

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();
const db = admin.firestore();
.
.
.

Console

✔  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: Invalid contents in the credentials file
    at FirebaseAppError.FirebaseError [as constructor] (/Users/shayana/Documents/calleWork/calle/functions/node_modules/firebase-admin/lib/utils/error.js:42:28)
    at FirebaseAppError.PrefixedFirebaseError [as constructor] (/Users/shayana/Documents/calleWork/calle/functions/node_modules/firebase-admin/lib/utils/error.js:88:28)
    at new FirebaseAppError (/Users/shayana/Documents/calleWork/calle/functions/node_modules/firebase-admin/lib/utils/error.js:123:28)
    at credentialFromFile (/Users/shayana/Documents/calleWork/calle/functions/node_modules/firebase-admin/lib/auth/credential.js:342:11)
    at new ApplicationDefaultCredential (/Users/shayana/Documents/calleWork/calle/functions/node_modules/firebase-admin/lib/auth/credential.js:307:32)
    at FirebaseNamespaceInternals.initializeApp (/Users/shayana/Documents/calleWork/calle/functions/node_modules/firebase-admin/lib/firebase-namespace.js:61:34)
    at FirebaseNamespace.initializeApp (/Users/shayana/Documents/calleWork/calle/functions/node_modules/firebase-admin/lib/firebase-namespace.js:408:30)
    at Object.<anonymous> (/Users/shayana/Documents/calleWork/calle/functions/index.js:14:7)
    at Module._compile (internal/modules/cjs/loader.js:936:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:947:10)

Upvotes: 0

Views: 1401

Answers (1)

Kian
Kian

Reputation: 314

Based on what you've explained, and since the error you've received is about lack of credential, I really doubt that it has something to do with the function itself.

I can suggest two thing:

First: Update firebase-admin package,

Second: Set the service account and GOOGLE_APPLICATION_CREDENTIALS variable and initialize SDK explicitly following this procedure

Upvotes: 1

Related Questions