Skip to main content

Command Palette

Search for a command to run...

How to use Husky 9.1.7 in a Monorepo Project

... and have the pre-commit actually run

Updated
2 min read
How to use Husky 9.1.7 in a Monorepo Project
P
I am a full-stack developer specializing in React, Next.js, TypeScript, C#, .NET and Sitecore. I love working on back-end as well as front-end, writing documentation, finding solutions to problems, and writing technical blog posts to help others. I've been Sitecore certified and Coveo for Sitecore certified twice.

Every time I’ve added Husky to a project, specifically to add some pre-commit logic, I’ve always run into an issue where the pre-commit logic doesn’t run and the commit just goes through. If you’ve dealt with this problem before, you know there’s that one StackOverflow thread that says, “just use Husky V4 and it works bro!!!11!!”. It’s 2026, I am not going to depend on such an old version. In my most recent struggle with Husky, I was working on a Monorepo that looked like this:

- Root
  - Front-End
  - Back-End

My first thought was to install Husky in Root/Front-End, since that’s where the package.json is. Wrong. Husky uses git hooks, and git hooks need to be installed at the root of the repository. Let’s go through this together.

Solution

Using Husky 9.1.7, this is the only thing that worked for me:

  1. Navigate to the root of your monorepo in a terminal.

  2. Run npm i -D husky.

  3. Run npx husky init. This will create the .husky/ folder at the root of your project. (It will also overwrite .husky/pre-commit if you already have it.)

  4. Add or change your prepare script in package.json to this: git config core.hooksPath .husky/_. This will make Husky work correctly for other developers when they run npm install.

  5. I recommend installing lint-staged alongside Husky as it can run multiple commands on pre-commit. My config looked like this (put this in package.json):

       "lint-staged": {
         "*.{ts,tsx,js,jsx}": [
           "eslint --max-warnings=0",
           "prettier --write"
         ]
       }
    
  6. Finally, update the .husky/pre-commit file at the root of your monorepo project to something like this:

     cd Front-End
     npx --no-install lint-staged
    

Now, try committing a change and you should see Husky running.

Conclusion

Hope this helped you set up Husky in your monorepo project!

How to use Husky 9.1.7 in a Monorepo Project