sh husky command not found
Interview Questions practice on Codemia
Over 8,000 real interview questions from top companies, searchable by company and role.
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:
or with another package manager:
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:
Then inspect the installed package:
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:
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:
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 foundusually 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 huskyover assuming a global command. - Keep hook files,
preparescripts, and Husky version aligned. - CI failures often come from skipping dev dependencies intentionally or accidentally.
Related reading
- Should CSS always precede JavaScript?
- Should I add async/await to a single-line function or not?
- Should I always use redux-saga call effect for functions that return promise?
- Should I be using process.nextTick
- SHAP DeepExplainer with TensorFlow 2.4 error
- SHAP Exception Additivity check failed in TreeExplainer
- Should I check in folder node_modules to Git when creating a Node.js app on Heroku?
- Should I make HTML Anchors with 'name' or 'id'?
.png&w=3840&q=75)
Tackling System Design Interview Problems
A short course that equips you with the skills to approach system design interviews methodically.
Start the free courseTrack 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.