husky
command not found
shell script
troubleshooting
npm scripts

sh husky command not found

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

Introduction

The error sh: husky: command not found means a Git hook or script tried to execute husky, but the shell could not find that binary in the current environment. In most projects, the root cause is one of three things: Husky was never installed, dependencies were not installed, or the hook is calling Husky in a way that assumes a global executable.

Understand How Husky Is Usually Installed

Husky is typically a project-local development dependency, not a globally installed command. A common setup looks like this:

bash
npm install --save-dev husky

or with another package manager:

bash
yarn add --dev husky

The binary then lives under the project’s node_modules/.bin directory and is normally invoked through package manager scripts or through the generated hook files.

Check That Dependencies Exist

If the repository was cloned fresh and node_modules has not been installed, the hook may fail immediately.

Start with:

bash
npm install

Then inspect the installed package:

bash
npm ls husky

If Husky is not present, the hook cannot run it.

Verify the Hook Setup

Modern Husky setups usually create files under .husky/ and use the generated shell wrapper instead of expecting a globally available husky command inside every hook.

A typical project-level setup includes a prepare script in package.json so hooks are installed after dependencies are installed:

json
1{
2  "scripts": {
3    "prepare": "husky"
4  }
5}

Depending on the Husky version used by the project, the exact prepare command may differ, so match the project’s existing version rather than copying a snippet from a different major release blindly.

The key point is that the repo should bootstrap Husky through the local dependency, not through a global shell command installed elsewhere on your machine.

Run Commands Through the Package Manager When Appropriate

If you need to execute Husky manually, prefer package-manager-aware execution:

bash
npx husky

That resolves the local project binary when available. It is safer than assuming husky is on the global PATH.

If npx husky works but the hook still fails, inspect the hook file itself. It may contain an outdated command or a hard-coded environment assumption.

CI and Production Environments

This error is also common in CI where dev dependencies are skipped. If the pipeline installs only production dependencies, Husky will not be present.

In those environments, choose intentionally:

  • install dev dependencies so hooks can run, or
  • disable Husky in CI if hooks are not meant to execute there

The important part is consistency. Hooks that require local tooling will fail when that tooling is absent.

Common Pitfalls

The most common mistake is assuming Husky is global. In most projects, it is a local dev dependency.

Another issue is cloning a repository and running Git commands before installing dependencies. The hook fires, but node_modules/.bin/husky does not exist yet.

People also copy setup instructions across Husky major versions. Because Husky’s installation commands changed over time, version mismatch can leave hook files and package.json scripts out of sync.

Finally, do not debug shell PATH first if the package is not installed at all. Confirm the dependency exists before chasing environment details.

Summary

  • 'sh: husky: command not found usually means the local Husky binary is missing or not being invoked correctly.'
  • Install project dependencies and confirm Husky is present in node_modules.
  • Prefer project-local execution such as npx husky over assuming a global command.
  • Keep hook files, prepare scripts, and Husky version aligned.
  • CI failures often come from skipping dev dependencies intentionally or accidentally.

Related reading
Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Track what you have practised

A free account saves your progress, solutions and study plan across every problem on Codemia.

Interview Questions practice on Codemia

Over 8,000 real interview questions from top companies, searchable by company and role.

Browse interview questions

All Rights Reserved.