Description
The frontend/Dockerfile installs only production dependencies in the deps stage, but the builder stage needs dev dependencies (TypeScript, build tools) to compile:
# Stage 1: Dependencies
FROM node:20-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm ci --only=production # ← Only production deps
# Stage 2: Builder
FROM node:20-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules # ← Missing devDependencies
COPY . .
RUN npm run build # ← Fails: tsc, next build tools not available
Impact
npm run build fails in Docker because TypeScript compiler, Next.js build tools, PostCSS, Tailwind, etc. are in devDependencies
- Docker image cannot be built without modification
- CI/CD pipelines using this Dockerfile will fail
- The
builder stage has a second npm ci which may re-install deps, but only if package-lock.json is present, and it duplicates work
Suggested Fix
Install all dependencies in the deps stage, then prune for production in the final stage:
# Stage 1: Dependencies (all, including dev)
FROM node:20-alpine AS deps
WORKDIR /app
COPY package.json package-lock.json* ./
RUN npm ci # Install ALL dependencies
# Stage 2: Builder
FROM node:20-alpine AS builder
WORKDIR /app
COPY --from=deps /app/node_modules ./node_modules
COPY . .
RUN npm run build
# Stage 3: Runner (production only)
FROM node:20-alpine AS runner
WORKDIR /app
COPY --from=builder /app/.next ./.next
COPY --from=builder /app/public ./public
COPY package.json package-lock.json* ./
RUN npm ci --only=production # Only production deps for runtime
File
frontend/Dockerfile
Description
The
frontend/Dockerfileinstalls only production dependencies in thedepsstage, but thebuilderstage needs dev dependencies (TypeScript, build tools) to compile:Impact
npm run buildfails in Docker because TypeScript compiler, Next.js build tools, PostCSS, Tailwind, etc. are indevDependenciesbuilderstage has a secondnpm ciwhich may re-install deps, but only ifpackage-lock.jsonis present, and it duplicates workSuggested Fix
Install all dependencies in the
depsstage, then prune for production in the final stage:File
frontend/Dockerfile