Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

husky v9 lint-staged not triggered on pre-commit #1447

Open
chrisjbrown opened this issue May 19, 2024 · 6 comments
Open

husky v9 lint-staged not triggered on pre-commit #1447

chrisjbrown opened this issue May 19, 2024 · 6 comments

Comments

@chrisjbrown
Copy link

chrisjbrown commented May 19, 2024

Context
Please describe your issue and provide some context:

  • Mac
  • Iterm and VSCode
  • Hook doesn't run

husky 9.0.11
lint-staged 15.2.2

Used https://github.com/uulm-mrm/git_hooks to get a basic husky+lint-staged+prettier+eslint setup.
If I run npx lint-staged myself in a terminal I see the expected scripts run but committing doesn't trigger the scripts and allows the commit to go through.

Running git config core.hooksPath outputs .husky/_
git --version output git version 2.45.1

troubleshooting section says to be on git 2.9 which feels like a mistake as 2.45.1 is latest

package.json

"scripts": {
    ....
    "prepare": "husky"
},
...
"lint-staged": {
    "*.js": "eslint --cache --fix",
    "*.{js,mjs,css,md,hbs}": "prettier --write"
}

.husky/pre-commit

npx lint-staged
@chrisjbrown chrisjbrown changed the title Hooks not running husky v9 lint-staged not triggered on pre-commit May 19, 2024
@ghost
Copy link

ghost commented May 22, 2024

I also had the same problem

@orochi-kazu
Copy link

Any chance your package.json isn't in the root directory of your repo?

I thought mine was broken (which is how I came across this issue), but then I found an adjusted config from a similar repo, and it's working fine now. My change is just "prepare": "cd .. && husky", but that may be irrelevant for you 🤔

@shuo-hiwintech
Copy link

I also had the same problem

@vicasas
Copy link

vicasas commented Jun 13, 2024

I have been facing the same issue where Husky's execution suddenly stops working without apparent reason.

After investigating in my repository, I noticed that this error occurs in all Husky hooks, specifically when the following scenario happens:

  1. I initialize a project with Git using git init.
  2. I install Husky in the project following the standard recommendation.
  3. I delete the .git folder from the project using the command rm -rf .git.
  4. I reinitialize Git in the project with git init.
  5. I try to execute a Husky hook, but I observe that it stops working immediately.

To temporarily solve this issue, the only effective measure I have found is to reinstall Husky every time the .git folder is deleted.

I hope these detailed steps clarify the issue I have been experiencing with Husky in my repository.

PeterDaveHello added a commit to PeterDaveHelloKitchen/ChatALL that referenced this issue Jun 25, 2024
sunner pushed a commit to ai-shifu/ChatALL that referenced this issue Jun 30, 2024
Nazlai pushed a commit to Nazlai/vitest-sharing that referenced this issue Jul 2, 2024
@Lonli-Lokli
Copy link

Happens when I manually migrated v8 -> v9

@Lonli-Lokli
Copy link

Seems like the problem is Linux\Windows separator issue.
As part of migration Git config (located in .git/config file) has been changed, to reflect husky's simplified hooks path
before

[core]
 hooksPath = .husky

after

[core]
 hooksPath = .husky\\_

So if I change hooks path to .husky/_ - everything started to work again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants