Docker / Deployment

vite: not found / tsc: not found after NODE_ENV=production in Docker

The Docker build skipped devDependencies before running the frontend or TypeScript build.

Docker vite not found NODE_ENV productionDocker tsc not found npm ci productiondevDependencies skipped Docker build
Paste an error to match it against the wiki. / 粘贴报错后自动匹配。

Error text / 报错原文

  • vite: not found
  • tsc: not found
  • Cannot find module typescript

What it means

The Docker build skipped devDependencies before running the frontend or TypeScript build.

Most common causes

  • NODE_ENV=production set before npm ci
  • npm ci --omit=dev used in the build stage
  • Build tools are incorrectly stored in devDependencies for a single-stage image
  • AI-generated Dockerfile copied production patterns too early

Fastest fix

  • Install dependencies before setting NODE_ENV=production
  • Use a multi-stage build with devDependencies in the builder stage
  • Move runtime-only pruning after npm run build
  • Verify package-lock.json is committed

Safe fix

  • Separate builder and runtime images
  • Use npm ci for reproducible builds
  • Keep TypeScript/Vite in devDependencies but install them only in builder stage
  • Fail builds when lockfile is missing

What not to do

  • Do not move all devDependencies into dependencies as a blanket fix
  • Do not run npm install without a lockfile in CI
  • Do not build production assets inside the runtime-only stage

How to confirm the fix

Run the smallest reproducible command first, then retry the agent task only after authentication, quota, and tool discovery are stable.

node --version
npm ci
npm run build

Related errors

Related tools

Sources

Based on common developer troubleshooting patterns and linked EasyTool references.