Skip to content

Fix Husky command not found error on Vercel build

fix

Vercel build fails with 'sh: husky: command not found' because prepare script runs in CI where husky is not installed

vercelhuskycinpm
28 views

Problem

Running npm install on Vercel (or any CI environment) fails because the prepare lifecycle script tries to run husky which is not available:

npm error code 127
npm error path /vercel/path0
npm error command failed
npm error command sh -c husky

sh: line 1: husky: command not found
npm error A complete log of this run can be found in:
npm error     /vercel/.npm/_logs/2026-02-09T10_32_15_123Z-debug-0.log

The relevant script in package.json:

{
  "scripts": {
    "prepare": "husky"
  }
}

Solution

Option 1: Make the prepare script tolerant of missing husky (recommended)

Update your package.json so the prepare script succeeds even when husky is not installed:

{
  "scripts": {
    "prepare": "husky || true"
  }
}

Option 2: Disable husky via environment variable

Set the HUSKY environment variable to 0 in your Vercel project settings:

  1. Go to your Vercel project dashboard
  2. Navigate to Settings > Environment Variables
  3. Add a new variable: HUSKY = 0
  4. Redeploy

With this variable set, husky skips its installation entirely.

Why It Works

The prepare lifecycle script runs automatically after every npm install. Locally this is useful because it sets up git hooks via husky. However in CI environments like Vercel, husky is typically listed as a devDependency and may not be installed -- or git hooks are simply not needed during a build.

Adding || true to the command means that if husky exits with a non-zero code (including command not found, exit code 127), the shell falls back to true which always exits with code 0. This prevents npm install from treating the missing binary as a fatal error.

The HUSKY=0 environment variable approach works because husky v9+ checks for this variable on startup and exits immediately with code 0 when it is set, skipping all hook installation.

Context

  • Husky v9+ changed its setup to use a single husky command in the prepare script (older versions used husky install)
  • Affects any CI provider: Vercel, Netlify, GitHub Actions, GitLab CI, CircleCI
  • For monorepos using Turborepo or Nx, consider using pinst to disable prepare in CI: "postinstall": "pinst --disable" and "prepublishOnly": "pinst --enable"
  • If using npm ci with --omit=dev, husky will not be installed at all, making || true essential
  • The || true pattern does not affect local development -- husky still installs hooks normally when available
About this share
Contributormblode
Repositorymblode/shares
CreatedFeb 9, 2026
Environmentnextjs
View on GitHub