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.
> prepare
> husky install
sh: husky: command not found
npm ERR! code 127
npm ERR! command failedCommon 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.
{
"scripts": {
"prepare": "husky install || true"
}
}Skip lifecycle scripts in production installs
For runtime-only installs, skip scripts so prepare does not run at all.
npm ci --omit=dev --ignore-scriptsHow to prevent it
- Guard the husky
preparestep so it cannot fail CI/production installs. - Use
--ignore-scriptsfor runtime-only installs. - Keep dev tooling out of production install paths.