husky / prepare Script Fails in CI - Fix Git Hook Install in CI
husky installs Git hooks from a prepare script that runs after npm install. In CI it can fail when there is no .git directory or husky is missing from the install.
What this error means
npm install fails on the prepare lifecycle script with husky: command not found or a husky install error, often in a Docker build or a shallow checkout with no .git directory.
npm
> my-app@1.0.0 prepare
> husky install
sh: 1: husky: command not found
npm ERR! code 127Common causes
husky runs where there is no .git
In a Docker build or an export with no .git directory, husky install has no repo to attach hooks to and errors.
husky is not installed when prepare runs
With --production or --ignore-scripts off, husky may be absent or the prepare order is wrong, so the binary is missing.
How to fix it
Make prepare a no-op outside a Git repo
- Guard the prepare script so it skips when there is no .git or in CI.
- Keep hooks working for local developers.
package.json
"prepare": "husky install || true"Skip hook install in CI explicitly
- Set HUSKY=0 in CI to disable hook installation.
- Or run install with --ignore-scripts where hooks are not needed.
Workflow
env:
HUSKY: 0How to prevent it
- Guard the prepare script for environments without .git, set HUSKY=0 in CI and Docker builds, and ensure husky is installed before prepare runs so installs never break on hooks.
Related guides
husky "command not found" / prepare Script Fails in CIFix husky failing in CI - "husky: command not found" or a failing prepare script - when Git hooks try to inst…
husky ".husky/pre-commit: command not found" - Fix Hook Script in CIFix husky hooks failing with "command not found" in CI - a tool invoked by a hook is not on PATH, or the hook…
npm postinstall Script Failed in CI - Fix Failing postinstall HooksFix npm postinstall script failures in CI by finding what the hook actually runs (native build, download, cod…