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 · 9 comments
Open

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

chrisjbrown opened this issue May 19, 2024 · 9 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

@victor-paydestal
Copy link

Same issue. I've tried every solution that exists on the internet and it still doesn't work when I commit.

@Evavic44
Copy link

Evavic44 commented Feb 11, 2025

I couldn't get lint-staged to work with husky in my project, so I added a custom command to run lint and format in my project which now works when I make a commit. This is my config settings

{
  "scripts": {
  // other commands
  "lint": "eslint .",
  "prettier:format": "prettier --check . || prettier --write .",
  "preview": "vite preview",
  "prepare": "husky"
},

And my pre-commit hook

set -e

npm run prettier:format || true
npm run lint

Note

The -e flag allows the hook to only terminate when an error occurs (Mandatory to allow both commands to run). Here's the result.

code.format.showcase.mp4

It's not the cleanest solution but it's better than nothing at this point. Hopefully this could help someone.

@zlasa
Copy link

zlasa commented Mar 10, 2025

I am having the same issue but only when committing from VS Code. It appears it is using an older version of node, which I have no idea where it pulls it from.

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

8 participants