小工具知识网

当前位置: 首页 > 行业知识 > 【yarn】 ‘husky install‘ fails if ‘.git‘ directory does not exists解决方法

行业知识

【yarn】 ‘husky install‘ fails if ‘.git‘ directory does not exists解决方法

2026-11-16 07:53:57 来源:互联网转载

问题描述

���境:win10 + yarn 1.22.19

问题:在使用yarn安装前端依赖时,yarn install 出现错误:

.git can’t be found (see https://git.io/Jc3F9)

error Command failed with exit code 1.

截图

原因分析

根据设计,husky安装必须在与 .git 相同的目录中运行,但可以在准备脚本期间更改目录并传递子目录

解决方法

打开web目录下的package.json文件,修改如下字段:

将

"prepare": "husky install",

改成

"prepare": "cd .. && husky install web/.husky",

截图:

再次安装就成功啦。

C:\Users\***\Desktop\dormitory-management-Django\***\web>yarn installyarn install v1.22.19[1/5] Validating package.json...[2/5] Resolving packages...success Already up-to-date.$ cd .. && husky install web/.huskyhusky - Git hooks installedDone in 1.21s.

参考链接

上一篇:谷歌香港之旅,探索与揭秘的征程

下一篇:电脑版方舟游戏的下载指南