Skip to content
Latchkey

Node.js "husky install failed" (prepare script) in CI

The prepare script runs husky install on every npm install. In CI this fails when there is no .git directory, when husky was pruned, or when running inside a Docker build with no git context.

What this error means

An install step fails because the prepare script ran husky install and husky was missing or there was no git repo, aborting the whole install.

node
> prepare
> husky install

sh: husky: command not found
npm ERR! code 127
npm ERR! command failed

Common causes

husky not installed when prepare runs

With --omit=dev or a production install, husky is absent, but the prepare script still tries to run it and fails with exit 127.

No git directory in the build context

In a Docker build or a tarball install there is no .git, so husky has nothing to install into and errors.

How to fix it

Make prepare a no-op when husky is unavailable

Guard the prepare script so it skips husky in CI/production contexts.

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

Skip lifecycle scripts in production installs

For runtime-only installs, skip scripts so prepare does not run at all.

workflow
npm ci --omit=dev --ignore-scripts

How to prevent it

  • Guard the husky prepare step so it cannot fail CI/production installs.
  • Use --ignore-scripts for runtime-only installs.
  • Keep dev tooling out of production install paths.

Related guides

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