Skip to content
Latchkey

npm "missing script: build" in CI - Fix Undefined npm Scripts

npm run <name> looks up the script in package.json scripts. A missing-script error means there is no entry by that name in the package npm is running in.

What this error means

npm run build (or another name) fails immediately with missing script: build. The script exists in another package, or the job runs in a directory whose package.json has no such script.

npm
npm ERR! Missing script: "build"
npm ERR!
npm ERR! To see a list of scripts, run:
npm ERR!   npm run

Common causes

The script is not defined in this package.json

The scripts block has no build entry, or it is named differently (build:prod).

The job runs in the wrong workspace

In a monorepo the script lives in a different package than the one the step runs in.

How to fix it

Define or correct the script name

  1. List available scripts to confirm the exact name.
  2. Add the missing script or call the correct name.
Terminal
npm run
# add to package.json scripts:
# "build": "vite build"

Run in the right workspace

  1. Set working-directory to the package that defines the script.
  2. Or use a workspace filter to target it.
Terminal
npm run build --workspace=@acme/web

How to prevent it

  • Keep script names consistent across packages, document them, and run npm run in CI to surface the available list when a name is wrong.

Related guides

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