如何仅通过CLI设置Firebase项目的云资源位置
执行
firebase init storage报云资源位置未设置的命令行解决方法 报错信息
执行Storage初始化命令时触发报错:
Error: Cloud resource location is not set for this project but the operation you are attempting to perform in Cloud Storage requires it.
该报错触发原因是目标Firebase项目未配置默认云资源位置,Cloud Storage服务初始化强依赖该配置,无法跳过。
方案1:通过Firebase CLI配置(适配自动化脚本,无网页操作)
前置准备:已完成firebase login登录账号,且通过firebase use <你的项目ID>切换到待配置的目标项目。
执行配置命令:
firebase projects:update --location <目标位置ID>
常用可用位置ID参考:
us-central1:爱荷华,Firebase多服务默认推荐位置asia-east1:中国台湾asia-northeast1:日本东京asia-southeast1:新加坡europe-west1:比利时europe-west2:英国伦敦
注意:项目默认云资源位置一旦设置永久不可修改,配置前请确认位置符合业务延迟、数据合规要求
配置校验:执行firebase projects:info,返回结果中location字段显示为你设置的位置ID即为配置生效,之后重新执行firebase init storage即可正常初始化。
方案2:通过gcloud CLI配置
前置准备:本地已安装gcloud工具,完成账号登录,且通过gcloud config set project <你的项目ID>指定目标项目。
执行配置命令:
gcloud firebase project update --default-location <目标位置ID>
位置ID可选值和上述Firebase CLI方案一致。配置完成后可通过gcloud firebase project describe命令校验配置结果。
自动化脚本适配注意事项
- 两种CLI的配置命令均支持添加
--non-interactive参数,适配CI/CD等无交互运行场景 - 脚本中可提前查询项目当前位置配置,仅在未配置时执行更新操作,避免重复执行触发报错
- 位置ID建议提前定义为脚本变量,减少硬编码
内容的提问来源于stack exchange,提问作者Scorb
相关产品推荐
相关产品推荐

