Skip to content
Latchkey

pnpm "ELIFECYCLE prepare failed" in CI

A package ran its prepare script during pnpm install and that script exited non-zero. prepare runs for git dependencies and on local pack, so a build tool missing there fails the whole install.

What this error means

Install fails with ELIFECYCLE and "prepare: Exit status 1" for a specific package, usually a git or local dependency whose prepare runs a build that needs devDependencies.

node
ELIFECYCLE  Command failed with exit code 1.
.../node_modules/.../my-dep prepare: `tsc -p .`
.../node_modules/.../my-dep prepare: Exit status 1

Common causes

prepare needs missing devDependencies

The prepare script builds the package but its build tools are not installed in the CI context, so the script fails.

A git dependency builds on install

A git: or github: dependency triggers prepare to compile sources at install time, and that build broke.

How to fix it

Make prepare self-sufficient

Ensure the prepare script only uses tools the dependency declares, so it can build wherever it is installed.

  1. Run the failing prepare command locally to see the real error.
  2. Add any build tool the script needs to that package devDependencies.
  3. Prefer publishing a built package over a git dependency that builds on install.

Pin a published version instead of a git ref

Depend on a released version so no prepare build runs during install.

Terminal
pnpm add my-dep@1.4.0

How to prevent it

  • Avoid git dependencies that build via prepare in CI.
  • Keep prepare scripts self-contained with declared build tools.
  • Prefer published, prebuilt packages over install-time builds.

Related guides

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