Fix runtime stage: install prod deps instead of copying node_modules

pnpm uses a symlink-based virtual store (.pnpm/) that breaks when
copied between Docker stages — Node can't resolve modules from the
copied tree, causing 'Cannot find module express' at startup.

Replace the broken COPY with a proper pnpm install --prod in the
runtime stage. Layer caching still applies: manifests + lockfile
are copied before source so the install layer is only rebuilt when
deps change.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-29 22:12:38 -05:00
parent 84c9e5304e
commit 155e7849e1

View File

@@ -51,11 +51,18 @@ FROM node:22-alpine AS runtime
# Install tini for proper PID 1 signal handling # Install tini for proper PID 1 signal handling
RUN apk add --no-cache tini su-exec RUN apk add --no-cache tini su-exec
RUN corepack enable && corepack prepare pnpm@latest --activate
WORKDIR /app WORKDIR /app
# No native deps — runtime only needs node_modules for pure-JS packages (express, cors, etc.) # Copy workspace manifests and lockfile — pnpm needs these to install correctly
# pnpm hoists everything to the root node_modules (shamefully-hoist=true in .npmrc) COPY pnpm-workspace.yaml package.json pnpm-lock.yaml* .npmrc ./
COPY --from=server-builder /build/node_modules ./node_modules COPY apps/server/package.json ./apps/server/
COPY apps/client/package.json ./apps/client/
# Install production dependencies only — fresh install avoids broken symlinks
# from COPY-ing pnpm's virtual store between stages
RUN pnpm install --prod --frozen-lockfile
# Copy compiled server output (includes dist/db/migrations/*.js compiled by tsc) # Copy compiled server output (includes dist/db/migrations/*.js compiled by tsc)
COPY --from=server-builder /build/apps/server/dist ./apps/server/dist COPY --from=server-builder /build/apps/server/dist ./apps/server/dist