You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PowerShell中使用JSON文件设置Firebase Functions配置报错求助

问题解决:PowerShell下通过JSON文件设置Firebase Functions配置失败

报错原因

Error: Invalid argument, each config value must have a 2-part key (e.g. foo.bar).

该报错是因为Firebase Functions的配置系统要求所有配置项必须使用<命名空间>.<参数名>的二级及以上点分key结构,不支持直接给单个一级key赋值完整JSON字符串。同时当前使用的PowerShell语法中,$(cat env.json)输出的原始JSON串也不符合functions:config:set命令的参数格式要求。

解决方案

方案1:手动拆分配置项设置

如果你的env.json结构如下:

{
  "env": {
    "api_key": "abc123",
    "db_secret": "def456",
    "service_url": "https://example.com"
  }
}

直接将每个配置项转为点分key格式执行命令即可:
firebase functions:config:set env.api_key="abc123" env.db_secret="def456" env.service_url="https://example.com"

方案2:PowerShell脚本批量读取JSON设置

如果配置项较多,可以直接运行以下PowerShell脚本自动遍历JSON内容批量设置:

# 读取JSON文件内容
$envConfig = Get-Content -Path "env.json" -Raw | ConvertFrom-Json

# 遍历env下的所有配置项生成对应设置命令
$envConfig.env | Get-Member -MemberType NoteProperty | ForEach-Object {
    $configKey = "env.$($_.Name)"
    $configValue = $envConfig.env.$($_.Name)
    firebase functions:config:set "$configKey=`"$configValue`""
}

注意事项

  • 如果你的JSON存在更深层级的嵌套,比如env.service.auth.token,需要对应调整遍历逻辑,生成对应层级的点分key
  • 不要在PowerShell中使用单引号包裹包含变量的参数,会导致变量无法正常展开

内容的提问来源于stack exchange,提问作者Wesker

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 11:45:05