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:
- 修改
firebase.json:
"hosting": [ { "target": "default-site", "source": ".", "ignore": [ "firebase.json", "**/.*", "**/node_modules/**" ], "frameworksBackend": { "region": "us-central1" } }, { "target": "friendlychat", "source": ".", "frameworksBackend": {} } ],
- 更新
.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"] } } } }
操作步骤
- 保存修改后的配置文件
- 重新运行
firebase emulators:start,即可正常启动Hosting模拟器,看到预期的hosting: Local server: http://localhost:5000输出。
内容的提问来源于stack exchange,提问作者Koranke
相关产品推荐
相关产品推荐

