husky: Does not install git hooks when using yarn
When running yarn add husky --dev
, the git hooks do not get set up. I have to run the install script manually, and then it works fine.
Yarn version: 0.17.9
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 18
- Comments: 40 (6 by maintainers)
Commits related to this issue
- Ensure that Husky git hooks are installed after first install This documents how to enable git hooks after first install: `https://typicode.github.io/husky/#/?id=install` Normally you'd simply wri... — committed to shirakaba/plugin-seed by shirakaba 4 years ago
- chore: ensure Husky git hooks are installed after first install (#10) This documents how to enable git hooks after first install: `https://typicode.github.io/husky/#/?id=install` Normally you'd si... — committed to NativeScript/plugin-seed by shirakaba 4 years ago
- add: husky pre-commit hook 추가 - https://blog.pumpkin-raccoon.com/85 - https://github.com/typicode/husky/issues/84 — committed to boostcampwm-2022/web27-Wabinar by se030 2 years ago
Why is this closed? The actual issue is not solved, is still happening in:
When I try to run the above command, it fails:
Removing
.git/hooks
didn’t work either, neither adding it as a postinstall script did@typicode Encountering this again.
Yarn 1.9.4 npm 6.4.1 node v8.11.4 husky1.0.0-rc.14
To get around this and force it, I added to my package.json’s scripts:
I’m still having this issue:
after running
yarn add --dev husky --force
andcat .git/hooks/pre-commit
I’ve still gotcat: .git/hooks/pre-commit: No such file or directory
I’ve also tried running
install.js
directly from the command line vianode ./node_modules/husky/lib/commands/install
but that didn’t work either. That’s how thehusky
package is now structured; the above command errored for me.The hooks won’t get created for me either.
The hooks won’t run, install says it’s successful but it doesn’t create any hooks.
But when I commit, it immediately proceeds without running anything.
package.json:
I’ve spent a lot of time trying to figure out what is wrong, but the things are that they have changed the entire approach.
For those who are still struggling with this issue, and for newcomers: read Husky 5 Release announcement especially sections “Optional install” and “Config”:
Moreover, from the “Config” section:
dammit…
99.9999% of existing materials described husky integration become trash…
Getting the same issue as @Nikodermus here’s my setup:
Same problem here using 1.13.0 and latest version of husky
Hi @avaly,
Yes it will. I have a few ideas for this but need to do some testing.
Hi,
husky 5 has a breaking change regarding config, .huskyrc isn’t supported anymore. See docs for install or migration steps.
using the version ‘3.1.0’ solved my problem.
Just faced the same problem with yarn v0.24.5, same with fresh yarn cache (i.e. after
yarn cache clean
). Onlyyarn add --dev husky --force
helps.Can be reproduced on my booted.
Turns out husky v5 does not pull hooks from
package.json
anymore. You have to usehusky add [hook-name] [command]
In my opinion, that’s worse as it pollutes the tree with another set of plain script files, which contain the command itself, instead of abstracting the command into the runner… Also husky add doesn’t always
chmod
the file properly, so it’s more steps to make hooks work, plus they’re uglier now.@cat-walk you are experiencing that issue because you are not running that command through yarn so the script cannot infer your package manager name, the error is not very explicative in this case. Try adding:
to your package json and then run:
@Nikodermus Have you solved this problem?
So google can find it for the next guy:
husky hooks not working manually install
Execute this in your command line:
Same for us on https://github.com/decathlon/vitamin-web
For me it was git version. I’ve updated git version and it worked like charm. Make sure your
git
is> 2.13
I’ve encountered a few issues with it too 😦. Had to remove the hook manually from
.git/hooks/
thenyarn add husky --dev --force
to make it work.