From be6970cd812f1461453651c5a918a6970ecbd662 Mon Sep 17 00:00:00 2001 From: Konstantin Wohlwend Date: Sat, 18 Apr 2026 23:50:50 -0700 Subject: [PATCH] Fix Docker build scripts --- claude/CLAUDE-KNOWLEDGE.md | 3 +++ docker/backend/Dockerfile | 1 + docker/local-emulator/Dockerfile | 1 + docker/server/Dockerfile | 1 + 4 files changed, 6 insertions(+) diff --git a/claude/CLAUDE-KNOWLEDGE.md b/claude/CLAUDE-KNOWLEDGE.md index 970595b27..25d8af346 100644 --- a/claude/CLAUDE-KNOWLEDGE.md +++ b/claude/CLAUDE-KNOWLEDGE.md @@ -383,3 +383,6 @@ A: Next.js dev app-page runtimes (`app-page*.runtime.dev.js`) include their own Q: How can we replace the huge `next@16.1.7` patch file with a resilient install-time rewrite? A: Use a strict root `postinstall` script that rewrites only Next `>=16` app-page dev runtime bundles (`app-page*.runtime.dev.js`) from `doNotLimit=new WeakSet;async_hooks.createHook(` to the guarded `STACK_DISABLE_REACT_ASYNC_DEBUG_INFO` form. Guardrails should fail loud on marker mismatches, mixed guarded/unguarded states, replacement counts not equal to one, or missing runtime fingerprints; the script should also be idempotent (`patched=0, alreadyPatched>0` on second run). + +Q: Why can Turbo-pruned Docker builds fail with `Cannot find module /app/scripts/postinstall-patch-next-async-debug-info.mjs` during `pnpm install`? +A: In pruned builder stages, we copy `/app/out/json` and run `pnpm install` before copying `/app/out/full`. The root `package.json` still runs `postinstall: node ./scripts/postinstall-patch-next-async-debug-info.mjs`, but that script is not present yet. Fix by copying `scripts/postinstall-patch-next-async-debug-info.mjs` into the builder stage before `pnpm install` (for all Dockerfiles using the prune pattern). diff --git a/docker/backend/Dockerfile b/docker/backend/Dockerfile index fa53a1422..d94da602c 100644 --- a/docker/backend/Dockerfile +++ b/docker/backend/Dockerfile @@ -44,6 +44,7 @@ COPY .gitignore . COPY pnpm-workspace.yaml . COPY turbo.json . COPY configs ./configs +COPY --from=pruner /app/scripts/postinstall-patch-next-async-debug-info.mjs ./scripts/ RUN STACK_SKIP_TEMPLATE_GENERATION=true pnpm install --frozen-lockfile COPY --from=pruner /app/out/full/ . diff --git a/docker/local-emulator/Dockerfile b/docker/local-emulator/Dockerfile index 56deae788..4cb1ea7d6 100644 --- a/docker/local-emulator/Dockerfile +++ b/docker/local-emulator/Dockerfile @@ -42,6 +42,7 @@ COPY .gitignore . COPY pnpm-workspace.yaml . COPY turbo.json . COPY configs ./configs +COPY --from=pruner /app/scripts/postinstall-patch-next-async-debug-info.mjs ./scripts/ RUN --mount=type=cache,id=pnpm,target=/pnpm/store STACK_SKIP_TEMPLATE_GENERATION=true pnpm install --frozen-lockfile # copy over the rest of the code for the build diff --git a/docker/server/Dockerfile b/docker/server/Dockerfile index 8b5f8de19..c682c21e5 100644 --- a/docker/server/Dockerfile +++ b/docker/server/Dockerfile @@ -40,6 +40,7 @@ COPY .gitignore . COPY pnpm-workspace.yaml . COPY turbo.json . COPY configs ./configs +COPY --from=pruner /app/scripts/postinstall-patch-next-async-debug-info.mjs ./scripts/ RUN --mount=type=cache,id=pnpm,target=/pnpm/store STACK_SKIP_TEMPLATE_GENERATION=true pnpm install --frozen-lockfile # copy over the rest of the code for the build