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

Most upvoted comments

I was able to fix this issue with:

rm -rf .git/hooks/
npm i -D husky

Have you tried to do what error message suggests?

rm -rf .git/hooks/ npm i -D husky

This fixed it for me, thanks @AnimaMundi!

yes, try many times, including, reinstall the projects, interchange between yarn and npm, move the config into the package.json file, not working, and the wired thing is, I can find the package under node_modules/ folder

In addition to @AnimaMundi’s suggestion, I had to remove node_modules. All steps:

rm -rf .git/hooks/
rm -rf node_modules
yarn

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 me

Can't find Husky message appears in @next (not yet released) version Looks like you had installed @next and then tried to downgrade to 0.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 (via npm i or npm 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 why rm -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 for pre-commit hook.

PPS. I am back to here after four years (in 2024)! Here is what I needed to do:

npm un husky && rm -f .git/hooks/pre-commit && npm i -D husky && cat .git/hooks/pre-commit

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.

yarn remove husky
yarn add husky --dev
cd .git && rm -rf hooks
npm i -D husky@4.3.8
npm i -D husky

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 use npm first to setup the Git hooks:

rm -rf .git/hooks
rm -rf node_modules/

brew install git
npm i -D husky
ls .git/hooks

rm -rf node_modules
yarn install

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 space Project 2.0/project-app/node_modules/husky/run.js. I do not know much about shell scripts but I have added double quotes wherever the scriptPath was used and it worked. Bellow is the final pre-commit script.

scriptPath="script path"
hookName=`basename "$0"`
gitParams="$*"

if [ "${HUSKY_DEBUG}" = "true" ]; then
  echo "husky:debug $hookName hook started..."
fi

if [ -f "$scriptPath" ]; then
  node "$scriptPath" $hookName "$gitParams"
else
  echo "Can't find Husky, skipping $hookName hook"
  echo "You can reinstall it using 'npm install husky --save-dev' or delete this hook"
fi

Could you show .git/hooks/pre-commit file?