From 548b0fde9847b9aaa4e6b65bc8fadebbbadd5d36 Mon Sep 17 00:00:00 2001 From: Julia McGhee Date: Sat, 21 Mar 2026 21:44:07 +0000 Subject: [PATCH] Fix harness crash: load standalone config to skip webpack in production The standalone next package is trimmed and doesn't include webpack. The custom server.js was using next() which triggers config loading that requires webpack. Fix by extracting the standalone config at build time and setting __NEXT_PRIVATE_STANDALONE_CONFIG before requiring next, matching what the generated standalone server does. --- apps/harness/Dockerfile | 5 +++++ apps/harness/server.js | 19 ++++++++++++++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/apps/harness/Dockerfile b/apps/harness/Dockerfile index 8e76ac0..931d20d 100644 --- a/apps/harness/Dockerfile +++ b/apps/harness/Dockerfile @@ -25,6 +25,11 @@ COPY --from=deps /app ./ COPY packages/db ./packages/db COPY apps/harness ./apps/harness RUN pnpm --filter @homelab/harness build +# Extract standalone next config so the custom server can skip webpack loading +RUN node -e "\ + const s = require('fs').readFileSync('apps/harness/.next/standalone/apps/harness/server.js','utf8');\ + const m = s.match(/const nextConfig = (\\{.+\\})\n/);\ + require('fs').writeFileSync('apps/harness/.next/standalone/apps/harness/next-config.json', m[1]);" FROM base AS runner WORKDIR /app diff --git a/apps/harness/server.js b/apps/harness/server.js index 5c43248..ccf3015 100644 --- a/apps/harness/server.js +++ b/apps/harness/server.js @@ -1,13 +1,26 @@ const { createServer } = require("http"); +const path = require("path"); const { parse } = require("url"); -const next = require("next"); -const { attachPtyWebSocket } = require("./pty-server"); const dev = process.env.NODE_ENV !== "production"; const hostname = process.env.HOSTNAME || "0.0.0.0"; const port = parseInt(process.env.PORT || "3100", 10); -const app = next({ dev, hostname, port }); +// In production, load the standalone config to avoid webpack dependency +if (!dev) { + try { + const configPath = path.join(__dirname, "next-config.json"); + const nextConfig = JSON.parse(require("fs").readFileSync(configPath, "utf8")); + process.env.__NEXT_PRIVATE_STANDALONE_CONFIG = JSON.stringify(nextConfig); + } catch { + // Config not found (local dev) — next() will load config normally + } +} + +const next = require("next"); +const { attachPtyWebSocket } = require("./pty-server"); + +const app = next({ dev, hostname, port, dir: __dirname }); const handle = app.getRequestHandler(); app.prepare().then(() => {