-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Does husky v5 work at all in Windows? #864
Comments
Hi @robross0606, Yes, it should. What terminal are you using? Could you re-run with |
I encountered this same issue but resolved it. At first I had manually created my own blank #!/bin/sh
. "$(dirname "$0")/_/husky.sh" Once I prepended those lines to the file it seemed to start working without issue. |
It works for me with just the shebang line, which I think makes it consistent with other git hooks on Windows since they run in git bash (e.g. see https://stackoverflow.com/questions/18277429/executing-git-hooks-on-windows). |
That would make sense, I did not try with just the shebang. I originally found this issue thinking I had the same problem when I had no shebang in the file, just had the lines I wanted to run (lint-staged). |
Looking again at the It does seems like the migration documentation could be a lot clearer. I started looking at the v5 usage docs, not the migration docs, and if we had all tried to use the |
Does husky v6 fix this issue? |
@lauralouiset if you create them with I'll update docs in migration section to make it clearer that |
Ok, so I'm having ongoing issues with using husky (v6 at this point). I am using Windows. I have I have installed husky: npm i -D [email protected] I deleted my npx husky-init I added "prepare": "husky install" to my npm install I ran npx husky set .husky/pre-commit 'npx --no-install lint-staged'
npx husky add .husky/pre-commit 'npm run build'
npx husky add .husky/pre-commit 'git add dist/.' The first command cleared out the existing #!/bin/sh
. "$(dirname "$0")/_/husky.sh"
npx --no-install lint-staged
npm run build
git add dist/. And the following file structure (seen using git bash to run $ ls -lahR .husky/
.husky/:
total 6.0K
drwxr-xr-x 1 enemchik 1049089 0 Apr 1 13:51 ./
drwxr-xr-x 1 enemchik 1049089 0 Apr 1 13:52 ../
-rw-r--r-- 1 enemchik 1049089 2 Apr 1 13:51 .gitignore
drwxr-xr-x 1 enemchik 1049089 0 Apr 1 13:51 _/
-rwxr-xr-x 1 enemchik 1049089 100 Apr 1 13:51 pre-commit*
.husky/_:
total 1.0K
drwxr-xr-x 1 enemchik 1049089 0 Apr 1 13:51 ./
drwxr-xr-x 1 enemchik 1049089 0 Apr 1 13:51 ../
-rwxr-xr-x 1 enemchik 1049089 592 Oct 26 1985 husky.sh* I modified a file in my repository (one that would trigger git add .
git commit -m "test" and I get the following error: node:internal/modules/cjs/loader:927
throw err;
^
Error: Cannot find module 'C:\Program Files\Git\node_modules\npm\bin\npx-cli.js'
←[90m at Function.Module._resolveFilename (node:internal/modules/cjs/loader:924:15)←[39m
←[90m at Function.Module._load (node:internal/modules/cjs/loader:769:27)←[39m
←[90m at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)←[39m
←[90m at node:internal/main/run_main_module:17:47←[39m {
code: ←[32m'MODULE_NOT_FOUND'←[39m,
requireStack: []
}
husky - pre-commit hook exited with code 1 (error) I've spent hours googling this and one common thing i see people recommend is to check the Sometimes when i try to commit I will get a message that
In the first two cases in that list I also end up seeing a Stack trace:
Frame Function Args
000FFFFA628 001800644A0 (000FFFFA848, 00000000002, 00000000000, 000FFFFDE50)
000FFFFDE50 001800666CC (00000000064, 00000000000, 0000000020C, 00000000000)
000FFFFAD50 0018014AEE8 (00000000000, 00000000000, 00000000000, 00000000000)
000FFFFB150 001801750E4 (00180148FDE, 0018014F75F, 000FFFFB198, 00010000000)
000FFFFB150 001801471EB (00000010004, 00000000008, 000FFFFAF00, 00000000000)
000FFFFB150 00180219CB8 (00000000000, 00000000000, 00000000001, 001005D1D38)
000FFFFB150 0018021A112 (00100425DA8, 000FFFFB100, 000FFFFB0D8, 00000000006)
000FFFFB150 001800DAA25 (00000000000, 000FFFFB51C, 00000000009, 000FFFFFFFF)
000FFFFB150 0018014F925 (0080004A580, 00000000018, 00800046160, 00000000003)
00800046160 00180150F21 (00000080000, 00010000000, 0018014226B, 00000000014)
00800046160 0018014226B (00000080000, 00010000000, 0018014226B, 00000000014)
00800046160 0010041440F (0010000001F, 000FFFFC0E0, 00180069F2C, 00000000000)
0080004A580 001004C1E4F (000FFFFFFFF, 00000000000, 00000000000, 00800049AA0)
00000000000 00100415650 (000FFFFC120, 000FFFFFFFF, 00180175158, 00800049AA0)
00000000000 0010045A0E8 (001004D1164, 00000000004, 001005D6318, 00000000001)
00000000000 0010042FB73 (001800DA94C, 000FFFFC5A0, 0018023EF60, 001004D1E00)
00800049270 0010043484E (0009999000B, 000FFFFC5A0, 00100000048, 000FFFFC48C)
00000000000 00100435B40 (00000000000, 00000000000, 00000000000, 00000000000)
5000001000000002 00100437626 (00000000007, 00000000000, 00000000001, 00800049330)
5000001000000002 0010043777F (00000000000, 00000000040, 00800048BC0, 00000000000)
5000001000000002 00100430B31 (00100000000, 00100437720, 00800048C60, 00800048C60)
00000000007 00100430FC1 (00000000000, 000FFFFC720, 000FFFFC6C8, 00000000050)
001005D6558 001004393F6 (0000000001F, 00000000012, 00000000000, 00000000000)
00800049200 001004C11EC (000FFFFFFFF, 00000000000, 000FFFFCA90, 00800048D60)
00000000000 00100415650 (001004306B0, 00000000004, 00800048C00, 00800048D60)
000FFFFCA90 001004178E4 (001004CD548, 00000000004, 00800046A60, 001005DAEA8)
000FFFFCA90 00100401E1F (00000000002, 00000000001, 00000000001, 00000000008)
000FFFFCA90 001004BFB92 (000FFFFCC70, 00800000160, 00000000030, 8080808080808080)
000FFFFCCE0 0018004AF0A (00000000000, 00000000000, 00000000000, 00000000000)
000FFFFFFF0 00180048846 (00000000000, 00000000000, 00000000000, 00000000000)
000FFFFFFF0 001800488F4 (00000000000, 00000000000, 00000000000, 00000000000)
End of stack trace Some good news! I can replace the contents of my #!/bin/sh
echo "$(dirname "$0")/_/husky.sh" and see the following when I commit: > git commit -m "test"
.husky/_/husky.sh
[master 5421303] test
1 file changed, 1 insertion(+)
> however when I then change the exact same file I just changed (an .md file in my repo for testing commits) and rerun git add .
git commit -m "test" I see: > git commit -m "test"
/_/husky.sh
[master a10c59a] test
1 file changed, 1 deletion(-)
> (notice the different path output for the So nothing changed but a single .md file, and one commit shows I honestly suspect that this may not even be an issue with husky itself, but possibly with git bash. Oddly I only started having these issues after playing with husky@5. When I was using husky@4 i did not have these issues, however if I switch my repo back to husky@4 now I have similar issues (not identical, but essentially broken in the same functional way). I would chalk this up to a mistake I've made, and I would just assume I did something wrong, but a colleague did all the same steps documented above and has the exact same results I have. I'm open to any suggestions on how to get this resolved. For the moment our "solution" is we've got into the habit of running |
Just a small follow up, I tried https://github.com/toplenboren/simple-git-hooks as well and had similar issues, which really lead me to believe there's something going on with git bash or with my environment or configuration. Oddly though, my co-worker has the same issues (using husky) on his machine. I'm not really sure where to look to get this resolved though. |
I was having a similar issue while using the pre-commit hook on Windows WSL (windows terminal, zsh). This part doesn' work So I changed that to: I tested this on Windows WSL, Windows outside WSL, and macOS. Not sure if I am missing some configuration in WSL, @nemchik are you getting this through Windows WSL? Thanks |
The issue I am having is using |
I had issues too installing the latest husky (6.0.0) on Windows 10: I was following the "Usage" section in readme which says When following the section "Usage", "Automatic" on the documentation website however all worked like a charm: |
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. |
so what is the solution I am still having issue |
@ddublon have you tried #864 (comment)? |
I am using this template https://github.com/suren-atoyan/react-pwa/blob/master/.husky/pre-commit you see its the same as in the instructions |
It seems the newest version of husky does not require shebang at the top of the file, or including the husky script. |
I'm trying to migrate from v4 to v5 of Husky, but it completely fails to work when using git on Windows. All I get is:
But my repo includes a file called
pre-commit
in the.husky
folder.The text was updated successfully, but these errors were encountered: