部署Firebase Function遭遇Google服务器错误求助
问题详情
执行部署命令:npx firebase deploy --only functions:rewriter --project proj-staging --debug
该命令此前可正常运行,数小时后执行失败,报错核心内容:
[2024-06-19T08:55:24.882Z] <<< [apiv2][body] GET https://runtimeconfig.googleapis.com/v1beta1/projects/proj-staging/configs
502 That's an error.
The server encountered a temporary error and could not complete your request.Please try again in 30 seconds. That's all we know.
Unable to parse JSON: SyntaxError: Unexpected token < in JSON at position 0
[2024-06-19T08:55:24.883Z] Got unexpected error from Runtime Config; it has no status code: Unable to parse JSON: SyntaxError: Unexpected token < in JSON at position 0 {"name":"FirebaseError","children":[],"exit":1,"message":"Unable to parse JSON: SyntaxError: Unexpected token < in JSON at position 0","status":500,"level":"debug"}
已尝试但无效的操作:
- 移除Firebase上的对应Function
- 清理本地及CLI包
- 更新firebase-tools至最新版本
解决建议
1. 核查Runtime Config API状态与账号权限
- 登录GCP控制台,确认
proj-staging项目的Runtime Config API处于启用状态(搜索API库找到该服务,检查是否被意外禁用) - 重新认证CLI账号:执行
gcloud auth login,确保登录的账号对proj-staging项目拥有runtimeconfig.configs.list及相关部署权限
2. 规避GCP服务临时故障
虽然报错提示是临时错误,但部分区域服务可能延迟恢复:
- 尝试切换函数部署区域:在
firebase.json的functions配置中添加指定区域,比如:"functions": { "region": "us-central1", // 其他配置 } - 直接通过GCP控制台部署该函数,绕过Firebase CLI,验证是否是CLI层面的问题
3. 重置Runtime Config数据
若项目中存在损坏的Runtime Config项,会导致请求解析失败:
- 执行
gcloud runtime-config configs list --project proj-staging列出所有配置 - 删除可疑的配置(比如空配置、格式异常的项),再重新执行部署命令
4. 排查网络环境问题
本地代理、VPN可能篡改请求,导致返回HTML错误页而非JSON:
- 关闭代理或VPN,直接连接网络重试部署
- 检查本地hosts文件是否存在对
runtimeconfig.googleapis.com的异常映射
内容的提问来源于stack exchange,提问作者didi

