lint-staged not running on precommit

I tried so many solutions on here but a combination finally worked!

  1. Make sure Husky v4 is installed. v6 was never triggering for me.
  2. Check the output of git config core.hooksPath. This should not return anything. If it does run,
git config --unset core.hookspath

And FINALLY it worked!


The problem for me was I ran "npx mrm lint-staged" like the official website says but it only set the husky and lint-staged configurations in package.json. It does not add then as dependency or installed them.

The solution for me was:

  1. npm i -D husky lint-staged

  2. npx mrm lint-staged


In 2021

Sometimes hooks are not added by husky so you need to add it using a simple easy hack.

You need to uninstall husky first after that install V4 of husky because it ensures that your hooks are correctly installed and after that install the latest version of husky so you get the latest updates.

NPM

npm uninstall husky

npm install -D husky@4

npm install -D husky

YARN

yarn remove husky

yarn add -D husky@4

yarn add -D husky

If sometimes above trick not works, so let's add the hook into husky, below mention method is used only in V6 and I am showing the husky with lint-staged example.

NPM

npm install -D husky

npm set-script prepare "husky install" && npm run prepare

npx husky add .husky/pre-commit "npx lint-staged"

git commit -m "added husky and lint-stagged" // here you will notice the lint-staged checking the files with help of husky

YARN

yarn add -D husky

npm set-script prepare "husky install" && yarn prepare

npx husky add .husky/pre-commit "yarn lint-staged"

git commit -m "added husky and lint-stagged" // here you will notice the lint-staged checking the files with help of husky