From 2c84ce19dfae0bb1a49acd01a7f8ff53e87ad779 Mon Sep 17 00:00:00 2001 From: adevwithpurpose Date: Thu, 20 Aug 2026 23:34:00 +0500 Subject: [PATCH] fix(build): ensure standalone package.json declares module type for Node 24 worker compatibility (#10836) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Obrigado — corrige um warning real de runtime em produção sob Node.js 24: o package.json do standalone gerado pelo Next.js não declara "type": "module", forçando reparse de todo worker thread ESM (callLogArtifactWorker, onnxWorker) a cada spawn. Validação (worktree combinado a partir de origin/release/v3.8.50, 0 conflitos): - typecheck:core limpo, complexity/cognitive-complexity dentro do baseline - Confirmado que colocate-standalone.mjs escreve "type": "module" corretamente; testado sob Node 24.19.0, workers sobem sem warning de reparse --- scripts/build/colocate-standalone.mjs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/scripts/build/colocate-standalone.mjs b/scripts/build/colocate-standalone.mjs index 736527b8dd..d0298893f7 100644 --- a/scripts/build/colocate-standalone.mjs +++ b/scripts/build/colocate-standalone.mjs @@ -13,7 +13,7 @@ * * Run manually after a build, or automatically via the `postbuild` npm hook. */ -import { cpSync, existsSync, mkdirSync } from "node:fs"; +import { cpSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"; import { dirname, join } from "node:path"; import { execFileSync } from "node:child_process"; import { fileURLToPath } from "node:url"; @@ -107,3 +107,22 @@ for (const pkg of closure) { console.log( `[colocate-standalone] ✅ optional-dep closure: ${closure.length} packages (copied ${copied})` ); + +// 3) Ensure standalone package.json declares "type": "module" so Node 24 runs ESM worker bundles without warning +const standalonePkgPath = join(STANDALONE, "package.json"); +if (existsSync(standalonePkgPath)) { + try { + const rawPkg = readFileSync(standalonePkgPath, "utf8"); + const pkgJson = JSON.parse(rawPkg); + if (!pkgJson.type) { + pkgJson.type = "module"; + writeFileSync(standalonePkgPath, JSON.stringify(pkgJson, null, 2) + "\n", "utf8"); + console.log("[colocate-standalone] ✅ standalone package.json configured with type: module"); + } + } catch (err) { + console.warn( + "[colocate-standalone] ⚠️ could not update standalone package.json:", + err.message + ); + } +}