husky: git commit hooks never get created when husky v5 is installed
Installing husky 5 with npm i husky
doesn’t create the commit hooks when used with git version 2.20.1, node v14.15.4, and npm v6.14.10 on mac in a new project. I confirmed this by opening the .git folder for my project and checking the hooks folder, and it was unchanged after installation. I think I was having the same issue as several other people in this issue: https://github.com/typicode/husky/issues/326
I spent hours trying all the methods listed in that issue and the only one that worked was installing husky@4.2.3 which fixed the problem immediately, leading me to believe that there was a bug introduced in version 5. Please let me know if you need any other details.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 18 (4 by maintainers)
Commits related to this issue
- Migrate Husky from v4 to v5 https://typicode.github.io/husky/#/?id=migrate-from-v4-to-v5 Additional changes: - Use prepare script instead of postinstall: https://github.com/typicode/husky/pull/89... — committed to dita-ot/docs by infotexture 3 years ago
- Migrate Husky from v4 to v5 https://typicode.github.io/husky/#/?id=migrate-from-v4-to-v5 Additional changes: - Use prepare script instead of postinstall: https://github.com/typicode/husky/pull/89... — committed to dita-ot/website by infotexture 3 years ago
Hi @DouglasDev,
It’s normal behaviour with v5. You need to run
npx husky install
and create hooks withnpx husky add .husky/pre-commit ...
.You can check that it’s working by creating a new folder and running the following commands:
@typicode Thanks for your reply. I will take your word for it that it works, but that seems like this change in the installation process will confuse many developers since none the dozens of tutorials on the internet on how to add husky to a project (for example the create react app docs and the prettier docs) mention this. I guess this change is necessary for the improved performance/memory usage? Perhaps it would be helpful to show these instructions in the terminal after you install husky?
I added backslash as a workaround. npx husky add .husky/pre-commit \“npm run test\”
but it doesn’t work if it is put in package.json
In windows environments the same problem exists (see #871). In that case it can be solved by calling the locally installed version of husky (
.\node_modules\.bin\husky add .husky/pre-commit "echo hello"
). Seems to me like calling husky with npx has a path problem.Same issue here, we’re still using npm@6 on Windows 10 and the command
npx --no
is not yet available. On my side, I added 2 scripts in my “package.json” file :And thanks to that, my 2 files (with shebang as proposed here: https://github.com/typicode/husky/issues/864#issuecomment-778857821) are now triggered when I do
git commit -m "my commit message"
“.husky/commit-msg”:
“.husky/pre-commit”:
If it can help someone 😊
Thanks for this upgrade @typicode !
I have the same issue! I upgraded to
husky@5.0.9
and just noticed mypre-commit
andpre-push
hooks are not being triggered.They worked well with
husky@4.3.8
.my husky.config.js