【问题标题】:Firebase function onCall, response: Warning, FIREBASE_CONFIG environment variable is missing. Initializing firebase-admin will failFirebase 函数 onCall,响应:警告,FIREBASE_CONFIG 环境变量丢失。初始化 firebase-admin 将失败
【发布时间】:2019-09-29 13:29:19
【问题描述】:

我尝试从本地项目中调用我的测试函数。

但是当我打电话时,我总是遇到 401 错误。我不知道这里有什么问题,在前端我有带有 api 密钥的初始化应用程序,在 firebase 函数中我有admin.credential.applicationDefault(); 我试图通过admin.credential.cer(apiConfig),但这无济于事。

我还有环境变量GOOGLE_APPLICATION_CREDENTIALS,带有我的配置的路径。

依赖关系

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

我的功能

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;

});

前端函数请求

 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)
            });
    }

另外,我如何看到我拥有所有必需的标题

此处来自控制台的日志

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

【问题讨论】:

  • 您使用的是 Node 10 版吗?如果是这样,请参阅this open issue。您需要降级到 Node v8。
  • @BobSnyder ohhh goood,两天让我大吃一惊,非常感谢!
  • 以后,如果您有关于 Firebase CLI 的错误报告,请发布到项目 GitHub 而不是 Stack Overflow,或者向 Firebase 支持提交错误请求。 Stack Overflow 用于编程问题。

标签: firebase firebase-authentication google-cloud-firestore google-cloud-functions


【解决方案1】:

使用 Node v10 部署函数时会出现此错误。它是由bug in firebase-functions 引起的。有一个修复程序,但尚未发布。在此之前,通过更改 package.json 文件降级到 Node v8:

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

【讨论】:

    猜你喜欢
    • 2019-06-14
    • 2019-11-08
    • 1970-01-01
    • 2019-04-17
    • 1970-01-01
    • 2018-05-23
    • 2018-07-16
    • 2019-04-23
    • 1970-01-01
    相关资源
    最近更新 更多