Search code examples
javascriptprettierpre-commit-hooklint-staged

husk does not execute the precommit while I commit new files


I'm using husky v4.3.0 lint-staged 10.4.0 prettier v2.1 on create-react-app. package.json:

"husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "lint-staged": {
    "src/**/*.{ts, tsx}": [
      "eslint  --fix",
      "git add"
    ],
    "src/**/*.{ts, tsx, css, md, mdx, html}": [
      "prettier --write",
      "git add"
    ]
  },

I found a smiliar question lint-staged not running on precommit, I tried the different answers mentioned such as:

  • Delete the node modules and reinstall the packages
  • Rebuild the packages with npm rebuild
  • reinstall husky and lint-staged

Whenever I commit anything the lint-staged was not executed to run the lint and prettier. How can I fix that?


Solution

  • The problem is due to the git version. I used git v2.9.0 and husky v4 accepts git >= 2.13.0.

    Existing hooks are kept. Requires Node >= 10 and Git >= 2.13.0.

    Reference: https://github.com/typicode/husky/tree/master