Skip to content
Latchkey

npm "Cannot find module" After --omit=dev - Build Tool Stripped in CI

A production install (--omit=dev or NODE_ENV=production) drops devDependencies. If your build step needs a tool that lives there - TypeScript, a bundler, a plugin - the build then fails to find it.

What this error means

Install succeeds, but the build step crashes with Cannot find module for a build tool (e.g. typescript, vite, a webpack loader). It works in a normal install but breaks once --omit=dev strips devDependencies.

npm output
$ npm ci --omit=dev
$ npm run build
> tsc -p tsconfig.json
sh: 1: tsc: not found
npm error code 127

Common causes

Build tooling is in devDependencies but the build runs after a prod install

Compilers and bundlers are devDependencies by convention. A --omit=dev install removes them, so the build cannot run.

NODE_ENV=production implicitly omits dev deps

Setting NODE_ENV=production makes npm skip devDependencies even without --omit=dev, producing the same gap.

How to fix it

Install dev deps for the build, prune after

Do a full install to build, then prune to production for the runtime artifact.

Terminal
npm ci                 # includes devDependencies
npm run build
npm prune --omit=dev   # drop dev deps from the final image

Split build and runtime installs

  1. Run the build with a complete install (no --omit=dev).
  2. Produce the runtime image with npm ci --omit=dev over the built output.
  3. Do not set NODE_ENV=production for the build stage.

How to prevent it

  • Build with all deps; prune to production afterward.
  • Use multi-stage Docker to separate build and runtime installs.
  • Avoid NODE_ENV=production during the build step.

Related guides

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