【问题标题】:Error invoking firebase function referencing local configuration variables from Firebase Functions Shell从 Firebase Functions Shell 调用引用本地配置变量的 firebase 函数时出错
【发布时间】:2018-08-14 20:11:45
【问题描述】:

This is a continuation of troubleshooting this problem 以及与实施建议解决方案相关的单独问题。

我正在尝试从本地服务的环境 as outlined here 使用 Firebase 功能配置,但出现意外错误。

  1. 我在我的函数目录中创建了一个“.runtimeconfig.json”文件,其中包含以下内容:

{ “认证”:{ “clientid”:MY_CLIENT_ID, "signoutreturnto": SOME_URL, “响应类型”:SOME_URL, “redirecturi”:SOME_OTHER_URL, “范围”:SOME_OTHER_STRING, “域”:SOME_DOMAIN } }

  1. 我从 firebase CLI(在函数目录中)执行以下命令:

    • firebase 函数:config:get > .runtimeconfig.json
    • firebase 实验:函数:shell
  2. 我通过 cli 执行我的配置功能:

    配置()

  3. 我在控制台中得到以下错误输出:

配置()

TypeError: config is not a function
    at repl:1:1
    at ContextifyScript.Script.runInContext (vm.js:32:29)
    at REPLServer.defaultEval (repl.js:341:29)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.onLine (repl.js:536:10)
    at emitOne (events.js:96:13)
    at REPLServer.emit (events.js:191:7)
    at REPLServer.Interface._onLine (readline.js:241:10)
    at REPLServer.Interface._line (readline.js:590:8)

我的其他功能,bigben 和 firebaseConfig 按预期从 CLI 执行

【问题讨论】:

    标签: firebase google-cloud-functions firebase-cli


    【解决方案1】:

    您确定您使用的是最新版本的 firebase-tools 吗?您可以通过运行“npm install -g firebase-tools”进行更新。您应该在 v3.17.4 上,有一个已知错误已在该版本中得到解决。

    【讨论】:

    • 是的,我正在使用 v3.17.4
    【解决方案2】:

    如果你想在 CLI 模拟器提示符下查看你的函数配置,你应该从你的函数目录运行模拟器命令:

    $ cd functions
    $ firebase experimental:functions:shell
    

    然后,在 firebase 提示符下,您可以像这样访问您的配置:

    firebase> const functions = require('firebase-functions')
    firebase> functions.config()
    

    这应该打印你的配置。通常你不需要做这样的事情——你只需使用functions.config()从模拟函数内部读取配置。

    【讨论】:

    • 这解决了问题——但是为什么呢? config() 是 Firebase 中的保留名称吗?将我的方法名称从 config 更改为其他名称可以解决此解决方法吗?我的其他方法不这样做就可以工作。
    • CLI 不能用于调用代码中定义的任意 JavaScript 函数。它用于调用您的 index.js 通过文档中描述的接口导出的 Cloud Functions 代码。
    • 我的其他 Firebase 功能无需执行此操作即可工作。
    • 这是因为您的 Cloud Functions 已导出,这使得它们对 index.js 模块所需的代码可见。其他导出的函数对需要它的代码可见。他们实际上是私人的。同样,您试图以非预期的方式使用模拟器。如果你想对一些任意代码进行单元测试,有更好的方法来解决这个问题。
    猜你喜欢
    • 2021-07-16
    • 2018-10-15
    • 2018-10-10
    • 2018-08-04
    • 2018-07-09
    • 1970-01-01
    • 2021-06-02
    • 2018-07-07
    • 2017-11-29
    相关资源
    最近更新 更多