【问题标题】:Empty runtime config for firebase functions when running locally在本地运行时,Firebase 函数的运行时配置为空
【发布时间】:2021-10-28 07:20:04
【问题描述】:

所以我在本地运行函数时得到了臭名昭著的空函数config() ????

我得到的错误:

It looks like you're trying to access functions.config().stripe but there is no value there. You can learn more about setting up config here: https://firebase.google.com/docs/functions/local-emulator TypeError: Cannot read property 'test_token' of undefined

functions 文件夹调用以下命令:

firebase emulators:start --only functions

重要信息:

  • 我肯定是从函数运行模拟器/服务
  • 我做了 firebase 函数:config:get > .runtimeconfig.json 和 验证文件中确实有值
  • 我通过 CLI 验证我正在使用正确的 firebase 项目 也可以通过终端调用函数:config:get。
  • 当我尝试在本地运行时,我仍然得到一个空的配置文件 使我实际上根本无法运行我的功能(因为它们 依赖这些价值观)
  • 这些值肯定是在实际云配置中设置的(这不是一个新项目或任何东西)

firebase 模拟器:启动 --only 函数

我正在使用 firebase 函数版本:3.15.4

顺便说一句,我正在以这种方式访问​​配置:

import { config, config as firebaseConfig } from 'firebase-functions';
...
const runtimeConfig = config() as CloudRuntimeConfig;

其他想法:

这个项目集成了一些 webpack - 我不确定它是否相关,但只是将它添加到那里,因为它可能是相关的。

请!任何帮助将不胜感激 - 我即将失去它

【问题讨论】:

    标签: node.js firebase webpack google-cloud-functions


    【解决方案1】:

    问题是我的 package.json 将我指向 dist/ 文件夹:

    "main": "dist/index.js",

    因此,它正在那里寻找runtimeconfig.json 文件(在/dist 内)。

    解决方案是复制文件/在dist 中创建一个新文件,然后修复它!!

    【讨论】:

      【解决方案2】:

      根据文档 (here)。你需要运行

      firebase 函数:config:get > .runtimeconfig.json

      在您的函数目录中。

      【讨论】:

      • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 2023-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-10-22
      • 2021-04-09
      • 2021-08-13
      • 2019-10-21
      • 2020-07-30
      相关资源
      最近更新 更多