husky: Can't find Husky, skipping pre-commit hook
yarn in v1.6.0
husky installed information:
"husky": "^0.14.3"
config in .huskyrc
{
"hooks": {
"pre-commit": "npm run lint"
}
}
I got the below error message:
Can't find Husky, skipping pre-commit hook
You can reinstall it using 'npm install husky --save-dev' or delete this hook
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Reactions: 14
- Comments: 29 (4 by maintainers)
Commits related to this issue
- Creando tu primer servidor con Express.js Clase#17 https://platzi.com/clases/1646-backend-nodejs/22026-creando-tu-primer-servidor-con-expressjs/ https://github.com/typicode/husky/issues/333 — committed to gsuscastellanosSC/platzivideo by deleted user 5 years ago
- chore: rm -rf .git/hooks/ && npm i -D husky b/c husky-run is missing and suggested at [1]. [1]: https://github.com/typicode/husky/issues/333#issuecomment-431591451 — committed to niklaas/ng-table-cu by niklaas 3 years ago
I was able to fix this issue with:
Have you tried to do what error message suggests?
This fixed it for me, thanks @AnimaMundi!
yes, try many times, including, reinstall the projects, interchange between
yarn
andnpm
, move the config into thepackage.json
file, not working, and the wired thing is, I can find the package undernode_modules/
folderIn addition to @AnimaMundi’s suggestion, I had to remove node_modules. All steps:
The corrupted hooks were in my case most likely caused by switching from a branch with husky@1.1.2 to a branch with husky@0.14.3.
I just deleting the folder .git/hooks/ rm -rf .git/hooks/
working on windows
Upgrading to
husky@next
fixed it for meCan't find Husky
message appears in@next
(not yet released) version Looks like you had installed@next
and then tried to downgrade to0.14.3
. I guess, for proper downgrade one have to remove.git/hooks/...
files and reinstall husky.I believe it is because
husky
attaches its hooks from .huskyrc and only at the time of installation. So, if you try to first install husky (vianpm i
ornpm i -D husky
) and then create.huskyrc
file, it fails!You must reinstall husky, after
.huskyrc
is created (and possibly every time it is modified). That’s whyrm -rf .git/hooks && npm i -D husky
is the solution. 😃PS. If you don’t want to delete all the hooks, you can simply
rm -f .git/hooks/pre-commit
forpre-commit
hook.PPS. I am back to here after four years (in 2024)! Here is what I needed to do:
It recommends to:
npm install husky --save-dev
However, I needed to force the latest version to fix the issue:
npm install husky@latest --save-dev
That is of course if you are ok upgrading to the latest version. This error had occurred after I had just updated a bunch of npm packages, so grabbing the latest was ideal.
Simply uninstalling and reinstalling husky worked for me. My use case is a bit more complex because I’m using a Yarn workspace with husky installed in more than one sub-package, but the uninstall/reinstall cycle in just one of the sub-packages did the trick.
work for me~
2021, March. A receipt from 2018 has helped me. https://github.com/typicode/husky/issues/333#issuecomment-431591451 Thanks.
Was able to solve it by (manually) deleting the node_modules folder and the package-lock.json, then reinstalling. Working on Linux
Experiencing the same issue. Reinstalled a hundred times to not avail
For Yarn: Running
yarn add husky
may not display an error, for example when your Git is out of date, which will silently skip installing Husky’s Git hooks. So best to usenpm
first to setup the Git hooks:My server was still running which was locking
node_modules
. Once I shut down the server it installed successfully.@ianjamieson Thank you very much, he worked for me
I got the same error running on windows and it was caused by the fact that the
scriptPath
contained a white spaceProject 2.0/project-app/node_modules/husky/run.js
. I do not know much about shell scripts but I have added double quotes wherever thescriptPath
was used and it worked. Bellow is the final pre-commit script.Could you show
.git/hooks/pre-commit
file?