无法从GitHub添加Cordova插件问题求助
Cordova安装GitHub插件失败的解决方法
问题场景
执行以下命令安装Cordova蓝牙打印机插件:
cordova plugin add https://github.com/marcelo-michels/Cordova-Plugin-Bluetooth-Printer.git
错误输出
D:\Cordova\pos>cordova plugin add https://github.com/marcelo-michels/Cordova-Plugin-Bluetooth-Printer.git Failed to fetch plugin https://github.com/marcelo-michels/Cordova-Plugin-Bluetooth-Printer.git via registry. Probably this is either a connection problem, or plugin spec is incorrect. Check your connection and plugin name/version/URL. CordovaError: Error: npm: Command failed with exit code 1 Error output: npm ERR! code ENOENT npm ERR! syscall spawn git npm ERR! path git npm ERR! errno ENOENT npm ERR! enoent Error while executing: npm ERR! enoent undefined ls-remote -h -t https://github.com/marcelo-michels/Cordova-Plugin-Bluetooth-Printer.git npm ERR! enoent npm ERR! enoent npm ERR! enoent spawn git ENOENT npm ERR! enoent This is related to npm not being able to find a file. npm ERR! enoent npm ERR! A complete log of this run can be found in: npm ERR! C:\Users\willi\AppData\Roaming\npm-cache\_logs\2023-06-16T03_44_04_148Z-debug.log
错误原因
报错核心是npm ERR! enoent spawn git ENOENT,说明npm尝试调用git命令时找不到程序,原因是:
- 本地未安装Git
- Git已安装但未添加到系统环境变量中
解决步骤
- 检查Git安装状态:打开命令提示符/终端,输入
git --version,若提示“git不是内部或外部命令”,则需前往Git官方网站下载对应系统版本完成安装。 - 配置Git环境变量:
- 安装Git时务必勾选“Add Git to PATH”选项(默认安装会自动配置,手动安装遗漏则需手动添加)。
- 手动添加:找到Git安装目录下的
bin文件夹(示例路径:C:\Program Files\Git\bin),将该路径添加到系统环境变量的Path列表中。 - 重启命令提示符/终端,再次执行
git --version,确认能正常输出Git版本号。
- 重新执行插件安装命令:回到Cordova项目目录,再次运行
cordova plugin add https://github.com/marcelo-michels/Cordova-Plugin-Bluetooth-Printer.git。
内容的提问来源于stack exchange,提问作者williambernadi
相关产品推荐
相关产品推荐

