husky: Precommit hook fails inside Visual Studio 2019
Hi,
I have git version 2.24.1.windows.2
, husky 4.2.3
, VS2019 16.4.5
, pretty-quick 2.0.1
and husky
fails to run inside VS2019
only with the following message:
husky > pre-commit (node v12.14.0)
/c/[my_project_path_here]/ClientApp/node_modules/.bin/pretty-quick: line 5: cygpath: command not found
internal/modules/cjs/loader.js:800
throw err;
^
Error: Cannot find module 'C:\pretty-quick\bin\pretty-quick.js'
at Function.Module._resolveFilename (internal/modules/cjs/loader.js:797:15)
at Function.Module._load (internal/modules/cjs/loader.js:690:27)
at Function.Module.runMain (internal/modules/cjs/loader.js:1047:10)
at internal/main/run_main_module.js:17:11 {
code: 'MODULE_NOT_FOUND',
requireStack: []
}
husky > pre-commit hook failed (add --no-verify to bypass)
But it works perfectly fine from git bash
and other git clients like SourceTree and Tortoise. I’m not sure how can I run husky
in debug mode from VS so I can provide you with the debug log. With husky 3.1.0
it works just fine. Please let me know if you need more info. Thank you 😃
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 18
- Comments: 29 (1 by maintainers)
same issue but for GitHub Desktop for Windows
Also having this issue with GitHub Desktop.
A few of our staff use GitHub Desktop, hopefully this issue gets fixed. 3.1.0 is quite old.
I also have this issue. As suggested, downgrading Husky to 3.1.0 appears to fix it
@BarakMaozCIQ you have some workarounds posted above. You can change the script to be run on precommit with
npx pretty-quick --staged
Nope, it’s a problem of the used git distribution. cygpath seems also be missing in github desktop.
The included bash sets MSYS env, which causes the npm shell wrapper to use cygpath.
Hi! A brute solution is removing whatever hook (e.g.
husky
) folder located inside your.git
folderThis seems similar to https://stackoverflow.com/questions/61196309/husky-4-x-not-working-with-visual-studio-git, maybe try the solution from that link.
@aminya i know 😕 for me it looks like a npm issue too, because the generated shell wrapper scripts are not checking the existence of cygpath.
It’s a visual studio issue, in the included git version the cygpath.exe is missing.
https://developercommunity.visualstudio.com/t/Missing-cygpathexe-in-git/1393876
Try “husky”: { “hooks”: { “pre-commit”: “npx pretty-quick --staged” } }
https://stackoverflow.com/questions/61196309/husky-4-x-not-working-with-visual-studio-git
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Those who still have this issue. I migrated to
Lefthook
, and I am pretty happy with it.Well, I actually do this. Other people use Husky in their projects, and when I want to contribute to their projects, I get rid of the hooks first so I can commit a change! 🙄
You can also remove the
husky
entry from package.json@LloydTao Were you able to find a workaround solution?
same issue here