使用FlutterFire CLI配置Firebase到Flutter应用时遇项目列表获取失败求助
问题描述
执行 Firebase CLI 命令连接 Flutter 应用时出现以下错误:
i Found 0 Firebase projects.
FirebaseCommandException: An error occured on the Firebase CLI when attempting to run a command.
COMMAND: firebase projects:list --json
ERROR: Failed to list Firebase projects. See firebase-debug.log for more info.
已尝试创建新项目、安装 Node.js 和 FlutterFire CLI、firebase login --reauth 及重新登录,但问题仍未解决,执行 firebase projects:list 时提示认证方式已弃用且无法列出项目。
解决步骤
1. 升级 Firebase CLI 到最新版本
旧版本可能存在认证兼容问题,执行命令升级:
npm install -g firebase-tools
升级后验证版本:
firebase --version
2. 使用新 OAuth 流程重新认证
旧认证方式已弃用,执行以下命令触发新的浏览器认证流程:
firebase login --no-localhost
按照终端提示打开浏览器完成认证,确保登录账号拥有 Firebase 项目的访问权限。
3. 清理 Firebase CLI 缓存
缓存损坏可能导致项目列表加载异常,执行以下操作:
firebase logout rm -rf ~/.cache/firebase firebase login
Windows 用户替换清理命令为:
rmdir /s %USERPROFILE%\.cache\firebase
4. 手动指定项目 ID 配置 FlutterFire
若自动检测项目失败,直接使用项目 ID 完成配置:
flutterfire configure --project=你的项目ID
项目 ID 可在 Firebase 控制台的项目设置中查看。
5. 查看调试日志定位具体问题
若以上步骤无效,查看 firebase-debug.log 获取详细错误信息:
# Linux/macOS cat firebase-debug.log # Windows type firebase-debug.log
根据日志中的具体错误(如权限不足、网络代理问题)针对性处理,比如确认账号是否有项目读写权限、检查网络是否正常访问 Firebase 服务。
内容的提问来源于stack exchange,提问作者Suraj Raghuvanshi

