Firebase function onCall, response: Warning, FIREBASE_CONFIG environment variable is missing. Initializing firebase-admin will fail

。_饼干妹妹 提交于 2020-08-11 02:49:30

问题


I try to call my test function from local project.

But all time when i call, i take 401 error. I don't know what trouble here, in front end i have init app with api key, in firebase function i have admin.credential.applicationDefault(); I tried to pass admin.credential.cer(apiConfig), but this don't help to.

I also have Environment variable GOOGLE_APPLICATION_CREDENTIALS, with path to my config.

Dependencies

    "firebase-admin": "~7.0.0",
    "firebase-functions": "^2.2.0",
    "firebase-functions-test": "^0.1.6",

My function

import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';

admin.initializeApp({
    credential: admin.credential.applicationDefault(),
    databaseURL: "https://plan-list.firebaseio.com"
});

exports.createInviteUser = functions.https.onCall( (data, context)=> {

  return data;

});

Front-end function request

 createInviteUser(email: string) {
        let inviteFunction = firebase.functions().httpsCallable('createInviteUser');

        inviteFunction(email)
            .then((result) => {
            // Read result of the Cloud Function.
           console.log(result);
        })
            .catch(err=>{
                console.log(err)
            });
    }

Also, how i see i have all required headers

Here logs from console

12:54:58.063 PM
createInviteUser
Warning, FIREBASE_CONFIG environment variable is missing. Initializing firebase-admin will fail
12:55:36.257 PM
createInviteUser
Function execution started
12:55:36.257 PM
createInviteUser
 Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
12:55:36.271 PM
createInviteUser
Function execution took 15 ms, finished with status code: 204
12:55:36.573 PM
createInviteUser
Function execution started
12:55:36.573 PM
createInviteUser
Billing account not configured. External network is not accessible and quotas are severely limited. Configure billing account to remove these restrictions
12:55:36.951 PM
createInviteUser
Function execution took 379 ms, finished with status code: 401

回答1:


This error occurs when functions are deployed with Node v10. It is caused by a bug in firebase-functions. There is a fix but it is not yet released. Until it is, downgrade to Node v8 by changing your package.json file:

  "engines": {
    "node": "8"
  }


来源:https://stackoverflow.com/questions/56097912/firebase-function-oncall-response-warning-firebase-config-environment-variabl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!