Husky hooks not running in Lerna monorepo

Viewed 4847

I am working on a MonoRepo and one of the last things I am trying to automate is all my linting/formatting on code commits.

Currently I have most of my config in the root folder and I am extending them into the packages. If I run npm run precommit in the root directory I can see my packages being linted successfully.

The problem occurs when I stage and commit the code, husky hooks do not run and the commit goes through without following checks successfully

Folder Structure

- packages
  - bar/
    - dist
    - src
    package.json
    tsconfig.json
  - foo/
    - dist
    - src
    package.json
    tsconfig.json
.eslintrc
.prettierrc
package.json
tsconfig.json

Root Package.json

{
  "scripts": {
    "precommit:bar": "cd packages/bar && npm run precommit",
    "precommit:foo": "cd packages/foo && npm run precommit",
    "precommit": "npm-run-all precommit:*"
  },
  "husky": {
    "hooks": {
      "pre-commit": "npm run precommit"
    }
  },
  "lint-staged": {
    "**/*.{ts,tsx}": [
      "eslint --fix",
      "prettier --write"
    ]
  }
}

Inside each of the packages there is this script

"script": {
   "precommit": "lint-staged"
}
1 Answers

I had the same issue while using the latest husky package(5+).

I downgraded to version "husky": "^4.3.8",. It's working for me.

Validate here:

/Project/.git/hooks check hooks are created or not.

Related