From 1554161ab47ea1a02dea369eab8529c31c375cc5 Mon Sep 17 00:00:00 2001 From: Ho Ngoc Hai Date: Tue, 14 Apr 2026 02:04:58 +0700 Subject: [PATCH] =?UTF-8?q?fix:=20Web=20Dockerfile=20=E2=80=94=20rebuild?= =?UTF-8?q?=20pnpm=20symlinks=20in=20flatten=20stage?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pnpm standalone output has top-level symlinks pointing outside the dir. Copy .pnpm store (real files), then find+link each package correctly. Co-Authored-By: Claude Opus 4 (1M context) --- apps/web/Dockerfile | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/apps/web/Dockerfile b/apps/web/Dockerfile index 3a9adea..886aba6 100644 --- a/apps/web/Dockerfile +++ b/apps/web/Dockerfile @@ -18,12 +18,29 @@ COPY apps/web/ apps/web/ RUN cd apps/web && npx next build # ---- Flatten standalone ---- -# Next.js standalone with pnpm creates symlinks in node_modules. -# Use cp -rL to dereference symlinks into real files. +# Next.js standalone with pnpm creates symlinks that point outside the standalone dir. +# We copy .pnpm (real files), then fix symlinks to point to local .pnpm store. FROM node:22-slim AS flatten WORKDIR /app COPY --from=build /app/apps/web/.next/standalone/ /standalone/ -RUN cp -rL /standalone/node_modules /app/node_modules && \ + +# Copy .pnpm store (real files) and rebuild top-level symlinks +RUN cp -r /standalone/node_modules/.pnpm /app/node_modules/.pnpm 2>/dev/null || true && \ + # For each broken symlink in standalone/node_modules, find the package in .pnpm and link it + for link in /standalone/node_modules/*; do \ + name=$(basename "$link"); \ + [ "$name" = ".pnpm" ] && continue; \ + if [ -L "$link" ]; then \ + # Find the real package dir in .pnpm + real=$(find /app/node_modules/.pnpm -path "*/$name/package.json" -not -path "*/node_modules/.pnpm/*" 2>/dev/null | head -1); \ + if [ -n "$real" ]; then \ + ln -sf "$(dirname "$real")" "/app/node_modules/$name"; \ + fi; \ + elif [ -d "$link" ]; then \ + cp -r "$link" "/app/node_modules/$name"; \ + fi; \ + done && \ + # Copy server files from apps/web cp -r /standalone/apps/web/* /app/ 2>/dev/null || true && \ cp -r /standalone/apps/web/.next /app/.next 2>/dev/null || true && \ rm -rf /standalone