From 7bf399251da30679dcbbf3f91cd260e94a36f980 Mon Sep 17 00:00:00 2001 From: backryun Date: Sun, 28 Jun 2026 16:01:58 +0900 Subject: [PATCH] fix(cli): raise dev server Node heap limit to 8GB to prevent OOM (#5198) Integrated into release/v3.8.39 --- package.json | 2 +- tests/unit/dev-script-heap-limit.test.ts | 33 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 tests/unit/dev-script-heap-limit.test.ts diff --git a/package.json b/package.json index c50dbcc951..2c88af470b 100644 --- a/package.json +++ b/package.json @@ -71,7 +71,7 @@ }, "homepage": "https://omniroute.online", "scripts": { - "dev": "node scripts/dev/run-next.mjs dev", + "dev": "node --max-old-space-size=8192 scripts/dev/run-next.mjs dev", "prebuild:docs": "node scripts/docs/gen-openapi-module.mjs", "gen:provider-reference": "node --import tsx scripts/docs/gen-provider-reference.ts", "bench:compression": "node --import tsx scripts/compression/benchmark.ts", diff --git a/tests/unit/dev-script-heap-limit.test.ts b/tests/unit/dev-script-heap-limit.test.ts new file mode 100644 index 0000000000..336acbd35b --- /dev/null +++ b/tests/unit/dev-script-heap-limit.test.ts @@ -0,0 +1,33 @@ +import test from "node:test"; +import assert from "node:assert/strict"; +import fs from "node:fs"; +import path from "node:path"; +import { fileURLToPath } from "node:url"; + +// The dev server runs Next's bundler in-process via `node scripts/dev/run-next.mjs`. +// `--max-old-space-size` can only be set at process startup (not from inside the +// running process), so the heap ceiling has to live on the `node` invocation in +// the `dev` npm script. Without it, the dev bundler runs on V8's ~4GB default and +// OOMs while compiling heavy dashboard routes (e.g. /dashboard/providers, which +// pulls monaco / recharts / @lobehub/icons / xyflow / mermaid). The unit test +// suite already runs with 8192; the dev server must match. +const here = path.dirname(fileURLToPath(import.meta.url)); +const pkg = JSON.parse(fs.readFileSync(path.resolve(here, "../../package.json"), "utf8")); + +test("dev script raises the Node heap limit (matches the test suite's 8192)", () => { + const dev = pkg.scripts?.dev ?? ""; + assert.match( + dev, + /node\s+--max-old-space-size=8192\b/, + `dev script must launch node with --max-old-space-size=8192; got: ${dev}` + ); + // Guard ordering: the flag must precede the script path so node (not the script) + // receives it. + const flagIdx = dev.indexOf("--max-old-space-size"); + const scriptIdx = dev.indexOf("run-next.mjs"); + assert.ok(scriptIdx !== -1, "dev script must still launch run-next.mjs"); + assert.ok( + flagIdx !== -1 && flagIdx < scriptIdx, + "the heap flag must come before run-next.mjs so node receives it" + ); +});