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?