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

Firebase模拟器启动报错:解析无站点/目标名的托管目标断言失败

解决Firebase Emulator启动时的Hosting断言错误

问题场景

完成Firebase FriendlyChat Web应用教程第6步时,运行命令 firebase emulators:start 触发以下错误:

firebase emulators:start
i emulators: Starting emulators: auth, functions, firestore, hosting, storage
i emulators: Shutting down emulators.
i hub: Stopping emulator hub
Error: Assertion failed: resolving hosting target of a site with no site name or target name. This should have caused an error earlier

你的firebase.json中Hosting配置存在问题:数组内第一个站点条目既没有target也没有site标识,Firebase模拟器无法解析这个无标识的站点,导致断言失败。

解决方案

方案一(符合教程预期:单Hosting站点)

删除多余的无标识条目,保留带target: "friendlychat"的配置并补充必要的ignore规则(确保忽略不必要的文件),修正后的配置如下:

"hosting": [
  {
    "target": "friendlychat",
    "source": ".",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "frameworksBackend": {
      "region": "us-central1"
    }
  }
],

方案二(多Hosting站点需求)

如果确实需要两个站点,给第一个条目添加target属性,并在.firebaserc中注册对应target:

  1. 修改firebase.json:
"hosting": [
  {
    "target": "default-site",
    "source": ".",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ],
    "frameworksBackend": {
      "region": "us-central1"
    }
  },
  {
    "target": "friendlychat",
    "source": ".",
    "frameworksBackend": {}
  }
],
  1. 更新.firebaserc(替换your-project-id为你的实际项目ID):
{
  "projects": {
    "default": "your-project-id"
  },
  "targets": {
    "your-project-id": {
      "hosting": {
        "default-site": ["your-default-site-name"],
        "friendlychat": ["your-friendlychat-site-name"]
      }
    }
  }
}

操作步骤

  1. 保存修改后的配置文件
  2. 重新运行 firebase emulators:start,即可正常启动Hosting模拟器,看到预期的hosting: Local server: http://localhost:5000输出。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 07:04:55