From 09fdc5ccbe164fcbbab741c5ed93266cc9cadbff Mon Sep 17 00:00:00 2001 From: Ho Ngoc Hai Date: Tue, 14 Apr 2026 13:35:15 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20Web=20Dockerfile=20=E2=80=94=20use=20nod?= =?UTF-8?q?e-linker=3Dhoisted=20for=20flat=20node=5Fmodules?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pnpm default mode creates symlinks in node_modules that break when copied between Docker stages. Using node-linker=hoisted makes pnpm create flat node_modules (like npm), so Next.js standalone output contains real files instead of broken symlinks. Co-Authored-By: Claude Opus 4.6 (1M context) --- apps/web/Dockerfile | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile index 1a922be..689af1d 100644 --- a/apps/web/Dockerfile +++ b/apps/web/Dockerfile @@ -4,15 +4,19 @@ RUN corepack enable && corepack prepare pnpm@10.27.0 --activate WORKDIR /app # ---- Dependencies ---- +# Use node-linker=hoisted so pnpm creates flat node_modules (no symlinks). +# This ensures standalone output has real files, not broken pnpm symlinks. FROM base AS deps +RUN echo "node-linker=hoisted" > .npmrc COPY pnpm-lock.yaml pnpm-workspace.yaml package.json turbo.json ./ COPY apps/web/package.json apps/web/ RUN pnpm install --frozen-lockfile --filter @goodgo/web... # ---- Build ---- FROM base AS build +COPY --from=deps /app/.npmrc ./ COPY --from=deps /app/node_modules ./node_modules -COPY --from=deps /app/apps/web/node_modules ./apps/web/node_modules +COPY --from=deps /app/apps/web/node_modules ./apps/web/node_modules 2>/dev/null || true COPY tsconfig.base.json ./ COPY apps/web/ apps/web/ RUN cd apps/web && npx next build @@ -27,19 +31,11 @@ ENV NEXT_TELEMETRY_DISABLED=1 ENV HOSTNAME=0.0.0.0 ENV PORT=3000 -# Install production deps fresh (pnpm standalone output has broken symlinks) -COPY --from=deps /app/pnpm-lock.yaml /app/pnpm-workspace.yaml /app/package.json /app/turbo.json ./ -COPY --from=deps /app/apps/web/package.json ./apps/web/ -RUN corepack enable && corepack prepare pnpm@10.27.0 --activate \ - && printf '#!/bin/sh\nexit 0' > /usr/local/bin/husky && chmod +x /usr/local/bin/husky \ - && pnpm install --frozen-lockfile --filter @goodgo/web... --prod - -# Copy standalone server.js (the entrypoint Next.js generates) +# With hoisted node_modules, standalone output has real files (no symlinks) +COPY --from=build --chown=node:node /app/apps/web/.next/standalone/node_modules ./node_modules COPY --from=build --chown=node:node /app/apps/web/.next/standalone/apps/web/server.js ./server.js -# Copy .next build output COPY --from=build --chown=node:node /app/apps/web/.next/standalone/apps/web/.next ./.next COPY --from=build --chown=node:node /app/apps/web/.next/static ./.next/static -# Copy public assets if any exist (may be empty) COPY --from=build --chown=node:node /app/apps/web/public ./public EXPOSE 3000