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

Firebase生产环境部署报错:_d.map is not a function求助

解决Firebase Hosting生产环境部署时TypeError: _d.map is not a function错误

问题根源

报错源于convertConfig.js中对Hosting配置里headers字段的处理逻辑:代码尝试对deploy.config.headers调用map方法,但该值并非数组类型(可能是对象、null或其他非可迭代类型),直接触发map is not a function错误。开发环境正常是因为其firebase.json的headers配置格式符合要求,而生产环境配置存在格式错误。

常见错误场景及修复方案

1. headers配置为对象而非数组

检查你的firebase.json中hosting节点下的headers字段,正确格式必须是数组,每个元素是包含source(匹配规则)和headers(具体头信息数组)的对象:

{
  "hosting": {
    "headers": [
      {
        "source": "**/*.js",
        "headers": [
          {"key": "Cache-Control", "value": "public, max-age=31536000"}
        ]
      },
      {
        "source": "/index.html",
        "headers": [
          {"key": "Cache-Control", "value": "no-cache"}
        ]
      }
    ]
  }
}

如果你的配置写成了键值对形式的对象,就会触发错误:

// 错误示例
{
  "hosting": {
    "headers": {
      "**/*.js": {"Cache-Control": "public, max-age=31536000"},
      "/index.html": {"Cache-Control": "no-cache"}
    }
  }
}

修复:将headers改为数组格式,每个规则用对象包裹,严格遵循source + headers数组的结构。

2. headers字段值为无效类型

如果firebase.json中headers被误设为null、undefined或字符串等非数组类型,也会导致该错误:

// 错误示例
{
  "hosting": {
    "headers": null
  }
}

修复:删除无效的headers字段,或者替换为符合要求的数组格式。

3. Firebase CLI版本兼容性问题

你当前使用Node v14.18.1,建议检查Firebase CLI版本是否过旧——旧版本CLI可能对新配置格式的处理存在bug。执行以下命令更新CLI:

npm install -g firebase-tools

验证步骤

  1. 修正firebase.json中的headers配置格式
  2. 执行npm run build && firebase deploy --only hosting(指定仅部署Hosting,加快调试)
  3. 查看部署日志,确认错误是否消失

内容的提问来源于stack exchange,提问作者Sabrina B.

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 19:07:38