1

I am developing a cross platform app with nativescript and firebase and I have some cloud functions triggered onCreate and onWrite but when the functions are "cold" (after a longer time of inactivity) I get this error most of the time and the function fails to execute properly. Following requests do work, though.

Error: Unexpected error while acquiring application default credentials: Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information.
at GoogleAuth.<anonymous> (/user_code/node_modules/firebase-admin/node_modules/google-auth-library/build/src/auth/googleauth.js:229:31)
at step (/user_code/node_modules/firebase-admin/node_modules/google-auth-library/build/src/auth/googleauth.js:47:23)
at Object.next (/user_code/node_modules/firebase-admin/node_modules/google-auth-library/build/src/auth/googleauth.js:28:53)
at fulfilled (/user_code/node_modules/firebase-admin/node_modules/google-auth-library/build/src/auth/googleauth.js:19:58)
at process._tickDomainCallback (internal/process/next_tick.js:135:7)

My first three lines of functions.js look like this (as in the documentation):

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

I've tried using a service_account file generated from the console (as described here) but then I get a different error which I guess is because I'm running it on Googles servers and am not hosting it myself.

Any idea why this is happening and how I can prevent this?

1 Answer 1

1

With the new firebase-functions 1.x SDK, you initialize the Admin SDK like this:

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

Be sure you're using the latest version of that module.

Sign up to request clarification or add additional context in comments.

2 Comments

I've tried this and it seemed to work for a while but somehow the error spradically reappears and each time it does the function won't complete which is not acceptable.
Hey Doug, I've watched yoru Learn JavaScript Promises (Pt.1) video and I have the line admin.initializeApp(). I still get this error. I've also try to set GOOGLE_APPLICATION_CREDENTIALS environment variable and gcloud auth application-default login

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.