全局安装firebase-tools失败求助:npm命令执行报错
全局安装firebase-tools失败的解决方法
尝试执行npm install -g firebase-tools全局安装firebase-tools时失败,终端报错信息如下:
> npm install -g firebase-tools npm WARN deprecated @npmcli/move-file@2.0.1: This functionality has been moved to @npmcli/fs npm WARN deprecated har-validator@5.1.5: this library is no longer supported npm WARN deprecated uuid@3.4.0: 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 request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142 npm ERR! code 1 npm ERR! path C:\Users\berk.BERK-PC\Desktop\'~\.npm-global'\node_modules\firebase-tools\node_modules\protobufjs npm ERR! command failed npm ERR! command C:\Users\berk.BERK-PC\.cache\firebase\runtime/shell.bat -c -- node scripts/postinstall npm ERR! '--' is not recognized as an internal or external command, npm ERR! operable program or batch file. npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\berk.BERK-PC\AppData\Local\npm-cache\_logs\2023-11-09T22_29_32_163Z-debug-0.log
问题根源
报错核心是'--'不被识别为合法命令,且npm全局安装路径中包含非法单引号(Desktop\'~\.npm-global'),导致protobufjs的postinstall脚本执行时路径解析错误。
解决步骤
- 检查并修正npm全局路径配置
- 执行
npm config get prefix查看当前全局路径,确认是否存在多余单引号或非法字符 - 若路径异常,执行
npm config set prefix "C:\Users\berk.BERK-PC\.npm-global"(替换为无特殊字符的合法路径,去掉多余单引号);也可执行npm config delete prefix重置配置后重新设置
- 执行
- 清理npm缓存
执行npm cache clean --force清除缓存,避免残留配置干扰安装 - 重新安装firebase-tools
执行npm install -g firebase-tools,若仍失败,尝试以管理员权限打开命令提示符后再执行 - 备选方案(无需全局安装)
直接使用npx firebase-tools <具体命令>临时调用firebase-tools功能
内容的提问来源于stack exchange,提问作者skywalker
相关产品推荐
相关产品推荐

