Skip to content

Bug: Frontend Dockerfile installs only production deps — build stage fails #366

@gboigwe

Description

@gboigwe

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingdevopsCI/CD and infrastructure

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions