From d1bb4ddbb798d1a6108194fe4f48a31b1fb46a4a Mon Sep 17 00:00:00 2001 From: nataondev Date: Sun, 21 Jun 2026 16:01:25 +0700 Subject: [PATCH] fix(cli): handle Next.js 16 nested standalone output path (#1940) Next.js 16 nests standalone output under the project directory name when NEXT_TRACING_ROOT_MODE=workspace (e.g. standalone/9router/server.js instead of standalone/server.js), causing build-cli.js to fail with "Next.js standalone build not found". Detect nested layout with backward-compatible fallback to existing standalone/server.js and standalone/app/ paths. Co-authored-by: Cursor --- cli/scripts/build-cli.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cli/scripts/build-cli.js b/cli/scripts/build-cli.js index 48dd0910..625d94ba 100644 --- a/cli/scripts/build-cli.js +++ b/cli/scripts/build-cli.js @@ -135,7 +135,15 @@ console.log("✅ Cleaned\n"); console.log("3️⃣ Copying Next.js standalone build to app/cli/app..."); const standaloneRoot = path.join(appDir, ".next", "standalone"); const standaloneRootResolved = path.join(buildDistDir, "standalone"); -const standaloneRootToUse = fs.existsSync(standaloneRootResolved) ? standaloneRootResolved : standaloneRoot; +let standaloneRootToUse = fs.existsSync(standaloneRootResolved) ? standaloneRootResolved : standaloneRoot; +// Next.js 16 nests standalone output under the project name when NEXT_TRACING_ROOT_MODE=workspace +// e.g. .next-cli-build/standalone/9router/server.js +const pkgName = path.basename(appDir); +const nestedRoot = path.join(standaloneRootToUse, pkgName); +if (fs.existsSync(path.join(nestedRoot, "server.js")) && !fs.existsSync(path.join(standaloneRootToUse, "server.js"))) { + console.log(`ℹ️ Detected nested standalone output: ${pkgName}/`); + standaloneRootToUse = nestedRoot; +} const standaloneApp = fs.existsSync(path.join(standaloneRootToUse, "server.js")) ? standaloneRootToUse : path.join(standaloneRootToUse, "app");