Skip to content
Latchkey

husky "command not found" / prepare Script Fails in CI

husky installs Git hooks via a prepare lifecycle script. In CI - especially production installs or non-Git contexts - that script can fail because husky is absent or there is no Git repo to hook.

What this error means

An install fails on the prepare step with husky: command not found or a husky error. It typically happens with npm ci --omit=dev (husky is a devDependency) or inside a Docker build with no .git directory.

npm output
> myapp@1.0.0 prepare
> husky

sh: 1: husky: command not found
npm error code 127
npm error command failed

Common causes

husky is a devDependency but prepare runs in a prod install

The prepare script calls husky, but --omit=dev (or NODE_ENV=production) skipped installing it, so the command is missing.

No Git repository to attach hooks to

In a Docker build or a shallow/exported checkout without .git, husky has nothing to wire up and the prepare step errors.

How to fix it

Make prepare a no-op when husky is absent or in CI

Guard the prepare script so it skips gracefully outside a dev checkout.

package.json
// package.json
"scripts": {
  "prepare": "husky || true"
}

Skip lifecycle scripts in production installs

  1. Use npm ci --omit=dev --ignore-scripts for runtime-only images so prepare never runs.
  2. Or move hook setup out of the build path entirely (developer-machine only).
  3. Ensure husky is in devDependencies, since hooks are a developer concern.

How to prevent it

  • Guard the prepare script to tolerate CI and prod installs.
  • Use --ignore-scripts for production-only installs.
  • Keep husky a devDependency.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →