husky: Husky cannot execute hooks

version

husky: “^1.3.1”, os: Mac node: v10.7.0

.huskyrc

{
  "hooks": {
    "pre-commit": "npm run lint"
  }
}

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 27 (1 by maintainers)

Most upvoted comments

Hi, I had the same issue. The hooks didn’t work. Here’s what I did.

Make sure you understand it changes the valid location of hook files. If you’re not familiar with this, talk to your peer before you run the commands.

  1. Check where your git hooks are: $ git rev-parse --git-path hooks
  2. Then if it’s not .git/hooks, run git config core.hooksPath .git/hooks/ to solve the problem.

It seems like the hooks files are created in .git/hooks/ no matter what the core.hooksPath is.

same here, this is a recurring issue with husky. previous version of husky you could fix this by doing rm -rf .git/hooks and then installing husky npm install -D husky

this doesn’t work for me, but maybe it does for y’all.

check .git/hooks if it’s empty try to uninstall husky and install again. my sh history

 ls .git/hooks
 npm uninstall husky
 npm i husky -D
 ls .git/hooks

it helped me

THIS WORKED!!!

in the package.json file"

“husky”: { “hooks”: { “pre-commit”: “npm test”, “commit-msg”: “commitlint -E HUSKY_GIT_PARAMS” } },

first,you shoule check the .git/hooks if there are some hooks,such as pre-commit ,and check its content,if husky is corrected configed,you can see some content second,if the .git/hook does not has hooks,that means husky isnt take place.you shoule reinstall husky.for me at this moment i find the problem

when i uninstall husky,the terminal show: Husky requires Git >= 2.13.2, please update Git so i update my git and reinstall husky, everything is ok

I am having the same issue but this is how it worked for me without specifying the custom hook inside package.json on React

OS: Windows 10 Node: v14.16.1 husky: ^6.0.0

  1. npm install husky --save-dev
  2. npx husky install
  3. npx husky add .husky/pre-commit "npm run test"
  4. git commit -m"custom message"

doesn’t work for me

Yup, deleting .git/hooks directory and reinstalling husky did it for me.

Is there any reason why this runs this way? Is there no command that we can run within husky to check and create the hooks?

Do you also have to do the same thing every time you change your hooks? It seems a bit inconvenient if that’s the case.

Maybe we can submit an MR to get around the issue?

Still getting the above issue with Windows 10 / Husky 6.0.0

Hi, I had the same issue. The hooks didn’t work. Here’s what I did.

Make sure you understand it changes the valid location of hook files. If you’re not familiar with this, talk to your peer before you run the commands.

1. Check where your git hooks are: `$ git rev-parse --git-path hooks`

2. Then if it's not `.git/hooks`, run `git config core.hooksPath .git/hooks/` to solve the problem.

It seems like the hooks files are created in .git/hooks/ no matter what the core.hooksPath is.

Thanks it’s worked for me.

add your script into package.json like this for instance: { “scripts”: {

  • “precommit”: “npm test”,
  • “commitmsg”: “commitlint -E GIT_PARAMS” }, and then run this command line:

npx --no-install husky-upgrade

to automatically upgrade your configuration, then try again, it works for me.

@danielhdz56 this does fix it for me. thank you!

Same here.

husky: “^1.3.1” os: Windows 10 node: v10.15.0

There is no custom hooks that prevents Husky.