我们在终端敲自动配置命令时 npx husky-init && npm install
会出现以下报错信息:我们预期是敲上面的文件跟根目录会多出 .husky 文件夹
"husky install" command already exists in prepare script, skipping.
/Users/982471938qq.com/Desktop/superSmall/shop-cms/node_modules/husky-init/node_modules/husky/lib/index.js:22
throw new Error(`.git can't be found (see ${url})`);
^
Error: .git can't be found (see https://typicode.github.io/husky/#/?id=custom-directory)
at install (/Users/982471938qq.com/Desktop/superSmall/shop-cms/node_modules/husky-init/node_modules/husky/lib/index.js:22:15)
at Object.<anonymous> (/Users/982471938qq.com/Desktop/superSmall/shop-cms/node_modules/husky-init/lib/bin.js:16:21)
解决方案:
1.首先检查是否有 .git 对git做一个初始化操作
git init
2.最后在输入这个命令
npx husky-init
3.husky 文件就创建成功了