typicode / husky

Git hooks made easy 🐢 woof!
https://typicode.github.io/husky
MIT License
31.75k stars 999 forks source link

husky pre-commit hook problem in windows #720

Closed zeitamin closed 2 years ago

zeitamin commented 4 years ago

as a windows user I have a hard time to configure it to work, the hooks works on WSL, but not in git bash nor in Powershell.

this is the command I ran

$ HUSKY_DEBUG=1 yarn add -D husky
$ HUSKY_DEBUG=1 git commit # ...

the output:

$ HUSKY_DEBUG=1 yarn add -D husky
yarn add v1.22.4
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] Resolving packages...
warning firebase-tools > google-auto-auth > request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
[2/4] Fetching packages...
info fsevents@2.1.2: The platform "win32" is incompatible with this module.
info "fsevents@2.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@1.2.9: The platform "win32" is incompatible with this module.
info "fsevents@1.2.9" is an optional dependency and failed compatibility check. Excluding it from installation.
info fsevents@2.1.3: The platform "win32" is incompatible with this module.
info "fsevents@2.1.3" is an optional dependency and failed compatibility check. Excluding it from installation.
[3/4] Linking dependencies...
warning " > bootstrap@4.4.1" has unmet peer dependency "jquery@1.9.1 - 3".
warning " > bootstrap@4.4.1" has unmet peer dependency "popper.js@^1.16.0".
warning " > react-ga@2.6.0" has unmet peer dependency "prop-types@^15.6.0".
warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
[4/4] Building fresh packages...
success Saved lockfile.
success Saved 191 new dependencies.
info Direct dependencies
β”œβ”€ @types/express@4.17.6
β”œβ”€ @types/node@12.12.37
β”œβ”€ firebase-tools@7.16.2
β”œβ”€ husky@4.2.5
β”œβ”€ picostyle-react@0.0.1
β”œβ”€ picostyle@2.2.0
β”œβ”€ prettier@1.19.1
β”œβ”€ pretty-quick@2.0.1
└─ pusher-js@5.1.1
info All dependencies
β”œβ”€ @google-cloud/paginator@2.0.3
β”œβ”€ @google-cloud/precise-date@1.0.3
β”œβ”€ @google-cloud/projectify@1.0.4
β”œβ”€ @google-cloud/promisify@1.0.4
β”œβ”€ @google-cloud/pubsub@1.7.2
β”œβ”€ @grpc/grpc-js@0.6.18
β”œβ”€ @types/body-parser@1.19.0
β”œβ”€ @types/color-name@1.1.1
β”œβ”€ @types/connect@3.4.33
β”œβ”€ @types/duplexify@3.6.0
β”œβ”€ @types/express@4.17.6
β”œβ”€ @types/fs-extra@8.1.0
β”œβ”€ @types/mime@2.0.1
β”œβ”€ @types/node@12.12.37
β”œβ”€ @types/qs@6.9.1
β”œβ”€ @types/range-parser@1.2.3
β”œβ”€ @types/serve-static@1.13.3
β”œβ”€ agent-base@6.0.0
β”œβ”€ ansi-align@2.0.0
β”œβ”€ ansicolors@0.3.2
β”œβ”€ archiver@3.1.1
β”œβ”€ array-differ@3.0.0
β”œβ”€ arrify@2.0.1
β”œβ”€ basic-auth-connect@1.0.0
β”œβ”€ basic-auth@2.0.1
β”œβ”€ big-integer@1.6.48
β”œβ”€ bignumber.js@7.2.1
β”œβ”€ binary@0.3.0
β”œβ”€ bl@4.0.2
β”œβ”€ bluebird@3.4.7
β”œβ”€ boxen@1.3.0
β”œβ”€ buffer-crc32@0.2.13
β”œβ”€ buffer-indexof-polyfill@1.0.1
β”œβ”€ buffer@5.6.0
β”œβ”€ capture-stack-trace@1.0.1
β”œβ”€ cardinal@2.1.1
β”œβ”€ chainsaw@0.1.0
β”œβ”€ char-spinner@1.0.1
β”œβ”€ cjson@0.3.3
β”œβ”€ cli-boxes@1.0.0
β”œβ”€ cli-color@1.4.0
β”œβ”€ cli-spinners@2.3.0
β”œβ”€ clone@1.0.4
β”œβ”€ colors@1.0.3
β”œβ”€ compare-semver@1.1.0
β”œβ”€ compare-versions@3.6.0
β”œβ”€ compress-commons@2.1.1
β”œβ”€ configstore@5.0.1
β”œβ”€ connect-query@1.0.0
β”œβ”€ connect@3.7.0
β”œβ”€ crc@3.8.0
β”œβ”€ crc32-stream@3.0.1
β”œβ”€ create-error-class@3.0.2
β”œβ”€ cross-env@5.2.1
β”œβ”€ crypto-random-string@2.0.0
β”œβ”€ csv-streamify@3.0.4
β”œβ”€ cycle@1.0.3
β”œβ”€ defaults@1.0.3
β”œβ”€ didyoumean@1.2.1
β”œβ”€ duplexer2@0.1.4
β”œβ”€ duplexer3@0.1.4
β”œβ”€ es5-ext@0.10.53
β”œβ”€ es6-promise@4.2.8
β”œβ”€ es6-promisify@5.0.0
β”œβ”€ es6-weak-map@2.0.3
β”œβ”€ event-emitter@0.3.5
β”œβ”€ event-target-shim@5.0.1
β”œβ”€ exit-code@1.0.2
β”œβ”€ ext@1.4.0
β”œβ”€ eyes@0.1.8
β”œβ”€ fast-text-encoding@1.0.2
β”œβ”€ fast-url-parser@1.1.3
β”œβ”€ find-versions@3.2.0
β”œβ”€ firebase-tools@7.16.2
β”œβ”€ flat-arguments@1.0.2
β”œβ”€ fs-constants@1.0.0
β”œβ”€ fstream@1.0.12
β”œβ”€ gcp-metadata@0.6.3
β”œβ”€ glob-slash@1.0.0
β”œβ”€ glob-slasher@1.0.1
β”œβ”€ global-dirs@0.1.1
β”œβ”€ google-auto-auth@0.10.1
β”œβ”€ google-gax@1.12.0
β”œβ”€ google-p12-pem@2.0.4
β”œβ”€ got@6.7.1
β”œβ”€ gtoken@4.1.4
β”œβ”€ home-dir@1.0.0
β”œβ”€ https-proxy-agent@5.0.0
β”œβ”€ husky@4.2.5
β”œβ”€ ignore@5.1.4
β”œβ”€ import-lazy@2.1.0
β”œβ”€ inquirer@6.3.1
β”œβ”€ is-installed-globally@0.1.0
β”œβ”€ is-npm@1.0.0
β”œβ”€ is-path-inside@1.0.1
β”œβ”€ is-promise@2.2.2
β”œβ”€ is-redirect@1.0.0
β”œβ”€ is-retry-allowed@1.2.0
β”œβ”€ is2@2.0.1
β”œβ”€ jju@1.4.0
β”œβ”€ join-path@1.1.1
β”œβ”€ json-bigint@0.3.0
β”œβ”€ json-parse-helpfulerror@1.0.3
β”œβ”€ jsonparse@1.3.1
β”œβ”€ jsonschema@1.2.6
β”œβ”€ JSONStream@1.3.5
β”œβ”€ jsonwebtoken@8.5.1
β”œβ”€ jwa@1.4.1
β”œβ”€ klaw@1.3.1
β”œβ”€ latest-version@3.1.0
β”œβ”€ lazystream@1.0.0
β”œβ”€ listenercount@1.0.1
β”œβ”€ lodash._isnative@2.4.1
β”œβ”€ lodash._shimkeys@2.4.1
β”œβ”€ lodash.defaults@4.2.0
β”œβ”€ lodash.difference@4.5.0
β”œβ”€ lodash.flatten@4.4.0
β”œβ”€ lodash.includes@4.3.0
β”œβ”€ lodash.isarguments@3.1.0
β”œβ”€ lodash.isboolean@3.0.3
β”œβ”€ lodash.isinteger@4.0.4
β”œβ”€ lodash.isnumber@3.0.3
β”œβ”€ lodash.isobject@2.4.1
β”œβ”€ lodash.keys@2.4.1
β”œβ”€ lodash.once@4.1.1
β”œβ”€ lodash.snakecase@4.1.1
β”œβ”€ lodash.toarray@4.4.0
β”œβ”€ lodash.union@4.6.0
β”œβ”€ lodash.values@2.4.1
β”œβ”€ log-symbols@2.2.0
β”œβ”€ lowercase-keys@1.0.1
β”œβ”€ lru-queue@0.1.0
β”œβ”€ marked-terminal@3.3.0
β”œβ”€ marked@0.7.0
β”œβ”€ memoizee@0.4.14
β”œβ”€ morgan@1.10.0
β”œβ”€ mri@1.1.5
β”œβ”€ multimatch@4.0.0
β”œβ”€ nash@3.0.0
β”œβ”€ node-emoji@1.10.0
β”œβ”€ open@6.4.0
β”œβ”€ opencollective-postinstall@2.0.2
β”œβ”€ ora@3.4.0
β”œβ”€ p-defer@3.0.0
β”œβ”€ package-json@4.0.1
β”œβ”€ picomatch@2.2.2
β”œβ”€ picostyle-react@0.0.1
β”œβ”€ picostyle@2.2.0
β”œβ”€ pkginfo@0.3.1
β”œβ”€ please-upgrade-node@3.2.0
β”œβ”€ plist@3.0.1
β”œβ”€ prettier@1.19.1
β”œβ”€ pretty-quick@2.0.1
β”œβ”€ protobufjs@6.9.0
β”œβ”€ pseudomap@1.0.2
β”œβ”€ pusher-js@5.1.1
β”œβ”€ redeyed@2.1.1
β”œβ”€ registry-auth-token@3.4.0
β”œβ”€ registry-url@3.1.0
β”œβ”€ router@1.3.5
β”œβ”€ rsvp@3.6.2
β”œβ”€ semver-compare@1.0.0
β”œβ”€ semver-diff@2.1.0
β”œβ”€ semver-regex@2.0.0
β”œβ”€ stack-trace@0.0.10
β”œβ”€ strip-final-newline@2.0.0
β”œβ”€ superstatic@6.0.4
β”œβ”€ supports-hyperlinks@1.0.1
β”œβ”€ tar-stream@2.1.2
β”œβ”€ tcp-port-used@1.0.1
β”œβ”€ term-size@1.2.0
β”œβ”€ timed-out@4.0.1
β”œβ”€ toxic@1.0.1
β”œβ”€ traverse@0.3.9
β”œβ”€ try-require@1.2.1
β”œβ”€ typedarray-to-buffer@3.1.5
β”œβ”€ unique-string@2.0.0
β”œβ”€ universal-analytics@0.4.20
β”œβ”€ unzip-response@2.0.1
β”œβ”€ unzipper@0.10.11
β”œβ”€ url-join@0.0.1
β”œβ”€ url-parse-lax@1.0.0
β”œβ”€ valid-url@1.0.9
β”œβ”€ wcwidth@1.0.1
β”œβ”€ which-pm-runs@1.0.0
β”œβ”€ widest-line@2.0.1
β”œβ”€ winston@1.1.2
β”œβ”€ write-file-atomic@3.0.3
β”œβ”€ xmlbuilder@9.0.7
β”œβ”€ xmldom@0.1.31
└─ zip-stream@2.1.3
Done in 39.67s.
$ HUSKY_DEBUG=1 git commit -m "test"
husky:debug husky v4.2.5 - pre-commit
husky:debug Current working directory is /d/workspace/aaaa/projectb
/usr/bin/bash: D:workspaceaaaprojectbnode_modules.binhusky-run: command not found
husky:debug yarn run --silent husky-run exited with 127 exit code
Can't find Husky, skipping pre-commit hook
You can reinstall it using 'npm install husky --save-dev' or delete this hook
husky:debug husky v4.2.5 - prepare-commit-msg
husky:debug Current working directory is /d/workspace/aaaa/projectb
husky:debug prepare-commit-msg config not found, skipping hook
husky:debug husky v4.2.5 - commit-msg
husky:debug Current working directory is /d/workspace/aaaa/projectb
husky:debug commit-msg config not found, skipping hook
husky:debug husky v4.2.5 - post-commit
husky:debug Current working directory is /d/workspace/aaaa/projectb
husky:debug post-commit config not found, skipping hook
[prettier f05c2ef] dsfsd
 1 file changed, 172 insertions(+), 153 deletions(-)
 rewrite src/components/pages/FeaturesPage.jsx (72%)
typicode commented 4 years ago

Hi @zeitamin,

what do you get if you manually run $ yarn run --silent husky-run pre-commit in projectb?

douglas-pires commented 3 years ago

Hey, @typicode... I'm having the same error, just to add something to the discussion, running the command you asked, I receive the following error:

/usr/bin/bash: C:UsersdouglDocumentsProjectsSomeProjectnode_modules.binhusky-run: command not found

What I've tried:

Using with Windows 10 Husky version: "husky": "^4.2.5"

I've tested with version 3 and it is running fine without it. I'll try to track the version that it started.

douglas-pires commented 3 years ago

Alright, it looks like it was introduced on 4.0.0-beta.0. Strangely, if I run yarn run --silent husky-run pre-commit it throws the same error, even in 3.1.0 which is the one that works. But committing by using VSCode works fine.

yekver commented 3 years ago

Have the same issue after migration to yarn (v1.22)

Using with Windows 7 Husky version: "husky": "^4.2.5"

mostafa-saeed commented 3 years ago

I have the same error on Win10. Here's the log from running HUSKY_DEBUG=1 git commit -m test:

husky:debug husky v4.0.10 (created at 8/6/2020, 10:51:00 PM)
husky:debug pre-commit hook started
husky:debug Current working directory is PROJECT_PATH
husky:debug pre-commit hook started
husky:debug npx --no-install husky-run exited with 0 exit code
husky:debug husky v4.0.10 (created at 8/6/2020, 10:51:00 PM)
husky:debug prepare-commit-msg hook started
husky:debug Current working directory is PROJECT_PATH
husky:debug prepare-commit-msg hook started
husky:debug npx --no-install husky-run exited with 0 exit code
husky:debug husky v4.0.10 (created at 8/6/2020, 10:51:00 PM)
husky:debug commit-msg hook started
husky:debug Current working directory is PROJECT_PATH
husky:debug commit-msg hook started
husky:debug npx --no-install husky-run exited with 0 exit code
husky:debug husky v4.0.10 (created at 8/6/2020, 10:51:00 PM)
husky:debug post-commit hook started
husky:debug Current working directory is PROJECT_PATH
husky:debug post-commit hook started
husky:debug npx --no-install husky-run exited with 0 exit code
[development 7ee9b6f] test
 1 file changed, 1 insertion(+), 1 deletion(-)

The change was in package.json file:

"pre-commit": "echo \"this should fail\" && exit 1"
Jojogervinho commented 3 years ago

I had the same problem on Win10 / git 2.27 / yarn 1.22.4 / husky 4.2.5 and found a solution that permits to run husky-run : npm config set script-shell "C:\\Windows\\System32\\cmd.exe" It's possible to use it with "C:\\Windows\\SysWOW64\\cmd.exe" or "C:\\Windows\\SysWOW64\\WindowsPowerShell\\v1.0\\powershell.exe" because the problem is with bash.exe which doesn't accept backslash path. Don't hesitate to execute npm config get script-shell before to know your previous script-shell (maybe null).

On my side, using cmd.exe or powershell.exe cause another problem with NODE_ENV so I need to juggle ...

Hope backslash path will be corrected and replaced by slash path as soon as possible !

matteoATDY commented 3 years ago

Removing .git/hooks folder and then running npm rebuild worked for me

SachinShekhar commented 3 years ago

This is an issue of Yarn (https://github.com/yarnpkg/yarn/issues/8340). See how to fix it: https://github.com/typicode/husky/issues/749#issuecomment-691531840

douglas-pires commented 3 years ago

Yep, using npm instead of yarn solved the issue.

SachinShekhar commented 3 years ago

@douglas-pires Yes, that's a temporary fix. Given npx runner is shipped with node.js, that should always work.

jlimadev commented 3 years ago

npm rebuild worked for me

Thank you!

robross0606 commented 3 years ago

The latest npm release appears to have broken this again. npm rebuild did not work. npx also doesn't work with the latest default 7.5.2 release of npm.

ghost91- commented 3 years ago

Having the same issue as @robross0606 but with npm v7.5.3 and on Linux.

Heatmanofurioso commented 3 years ago

Having the same issue with npm v7.5.3 on Windows too

rpidburachynskyi commented 3 years ago

I had this issue on WSL 2. After few hours of seeking answer I've decided to downgrade version from 5.0.9 to 4.3.8 (latest of 4.*) - and it's resolved my problem. Now I can add hooks.

Stanzilla commented 3 years ago

Same here with WSL2

ddsultan commented 3 years ago

In my case the latest version (5.x) of Husky on Windows 10 was the problem

stale[bot] commented 2 years ago

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.

Stanzilla commented 2 years ago

not stale

CasuallyCaffeinated commented 2 years ago

I'm running Husky v.7.04 on a WSL 2 machine and I don't seem to be having an issue. However, I'd like to know if there are still issue with using Husky on a Windows machine. Has there been any update to fix the previous issues?

typicode commented 2 years ago

@CasuallyCaffeinated the only known issue is https://typicode.github.io/husky/#/?id=yarn-on-windows (it may have been fixed since).

Otherwise no particular issue.

To avoid confusions, I'm going to lock this issue as it's an old one and concerns husky 4 which works quite differently than husky 7.

Feel free to create a new issue if needed :)