我在为我的项目配置 Flutter Fire 时遇到问题。我使用 npm install -g firebase-tools --force 安装,然后尝试 > dart pub global activate flutterfire_cli 但我仍然有 CLI 问题。我可以登录并查看版本,但无法运行 flutterfire configure
FirebaseCommandException: An error occured on the Firebase CLI when attempting to run a command.
COMMAND: firebase --version
ERROR: The FlutterFire CLI currently requires the official Firebase CLI to also be installed, see https://firebase.google.com/docs/cli#install_the_firebase_cli for how to install it.
阅读完 stackoverflow 和互联网上的所有主题后,我无法解决我的问题,有什么想法吗? 运行 npm install -g firebase-tools 我得到了这个:
> npm install -g firebase-tools
C:\Users\loveh\.cache\firebase\tools\firebase -> C:\Users\loveh\.cache\firebase\tools\node_modules\firebase-tools\lib\bin\firebase.js
+ [email protected]
updated 1 package in 11.091s
现在出现这个错误:
⠋ Fetching available Firebase projects...
Unhandled exception:
FormatException: Unexpected character (at character 1)
#
^
#0 _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1383:5)
#1 _ChunkedJsonParser.parseNumber (dart:convert-patch/convert_patch.dart:1250:9)
#2 _ChunkedJsonParser.parse (dart:convert-patch/convert_patch.dart:915:22)
#3 _parseJson (dart:convert-patch/convert_patch.dart:35:10)
#4 JsonDecoder.convert (dart:convert/json.dart:612:36)
#5 runFirebaseCommand (package:flutterfire_cli/src/firebase.dart:95:25)
<asynchronous suspension>
#6 getProjects (package:flutterfire_cli/src/firebase.dart:114:7)
<asynchronous suspension>
#7 ConfigCommand._selectFirebaseProject (package:flutterfire_cli/src/commands/config.dart:264:24)
<asynchronous suspension>
#8 ConfigCommand.run (package:flutterfire_cli/src/commands/config.dart:351:37)
<asynchronous suspension>
#9 CommandRunner.runCommand (package:args/command_runner.dart:209:13)
<asynchronous suspension>
#10 main (file:///C:/Users/loveh/AppData/Local/Pub/Cache/hosted/pub.dartlang.org/flutterfire_cli-0.2.2+2/bin/flutterfire.dart:57:5)
<asynchronous suspension>
新闻
npm install -g firebase-tools
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN config global `--global`, `--local` are deprecated. Use `--location=global` instead.
npm WARN deprecated [email protected]: this library is no longer supported
npm WARN deprecated [email protected]: Debug versions >=3.2.0 <3.2.7 || >=4 <4.3.1 have a low-severity ReDos regression when used in a Node.js environment. It is recommended you upgrade to 3.2.7 or 4.3.1. (https://github.com/visionmedia/d
ebug/issues/797)
npm WARN deprecated [email protected]: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: request has been deprecated, see https://github.com/request/request/issues/3142
changed 691 packages, and audited 692 packages in 36s
38 packages are looking for funding
run `npm fund` for details
25 vulnerabilities (15 moderate, 10 high)
To address issues that do not require attention, run:
npm audit fix
To address all issues (including breaking changes), run:
npm audit fix --force
Run `npm audit` for details.
删除之前安装的
firebase.exe
并仅依赖通过 firebase
安装的 npm install -g firebase-tools
。
该问题是由于安装冲突造成的。
如果出现
FormatException: Unexpected character (at character 1)
错误,请查看 flutter 主文件夹中是否有 firebase.exe 文件。这是我的问题。删除文件后,flutterfire configure
工作没有问题。
澄清: 由于之前的错误修复尝试,我已将 firebase-cli 二进制文件 (firebase-tools-instant-win.exe) 添加到我的 flutter 项目的主文件夹中,并将其重命名为 firebase.exe。如果您没有这样做,那么您的 flutter 主文件夹中应该没有 firebase 二进制文件。
在与大量错误作斗争后,通过执行以下操作为我解决了问题
确保您没有下载 Windows exe,因为在运行 firebase/flutterfire 时可能会发生冲突。对我来说,诀窍是确保我使用 nvm 来安装 npm,将 npm global 的默认目录安装设置为默认目录以外的目录。我相信这是一个许可问题。
只需将您的平台更新到最新版本 [windows 或 linux 或 mac] 它对我有用,希望它对某人有帮助
适用于 Windows 11 的解决方案 2023
firebase-tool-instant-win.exe
) 到“下载”文件夹您应该看到如下输出:
在 Firebase CLI 中使用
cd
(更改目录)命令访问 flutter 项目文件夹,与在 Windows cmd 中执行的操作相同。
仍然在 Firebase CLI 中运行以下命令:
dart pub global activate flutterfire_cli
如果输出显示
C:\Users\[USER]\AppData\Local\Pub\Cache\bin
不在您的路径上,您必须将其添加到路径中,然后重新启动电脑。要将其添加到您的路径中,请在 Windows 控制面板中搜索“路径”
别忘了重新启动!
flutterfire configure