From a8100e944455e6625d34c82623c01e2cb272ddb8 Mon Sep 17 00:00:00 2001 From: decolua Date: Thu, 14 May 2026 00:28:08 +0700 Subject: [PATCH] Fix build bug --- cli/package.json | 2 +- cli/scripts/build-cli.js | 23 ++++++++++++++++------- next.config.mjs | 11 ++++++++--- package.json | 2 +- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/cli/package.json b/cli/package.json index 7aca98d..0ec8bda 100644 --- a/cli/package.json +++ b/cli/package.json @@ -1,6 +1,6 @@ { "name": "9router", - "version": "0.4.38", + "version": "0.4.39", "description": "9Router CLI - Start and manage 9Router server", "bin": { "9router": "./cli.js" diff --git a/cli/scripts/build-cli.js b/cli/scripts/build-cli.js index 52f45a4..649cfff 100644 --- a/cli/scripts/build-cli.js +++ b/cli/scripts/build-cli.js @@ -90,12 +90,13 @@ appPkg.version = cliPkg.version; fs.writeFileSync(appPkgPath, JSON.stringify(appPkg, null, 2) + "\n"); console.log(`✅ Version synced: ${cliPkg.version}\n`); -// Step 1: Build app with Next.js +// Step 1: Build app with Next.js (workspace tracing root → traced node_modules in standalone). console.log("1️⃣ Building Next.js app..."); try { - execSync("npm run build", { + execSync("npm run build", { stdio: "inherit", - cwd: appDir + cwd: appDir, + env: { ...process.env, NEXT_TRACING_ROOT_MODE: "workspace" } }); console.log("✅ Next.js build completed\n"); } catch (error) { @@ -111,15 +112,23 @@ if (fs.existsSync(cliAppDir)) { console.log("✅ Cleaned\n"); // Step 3: Copy Next.js standalone build to app/cli/app. -// With outputFileTracingRoot = projectRoot, server.js + node_modules live flat under .next/standalone/. +// With workspace tracing root, Next places app files under .next/standalone/app/ and traced +// node_modules under .next/standalone/node_modules/ (slim, tracing-pruned). console.log("3️⃣ Copying Next.js standalone build to app/cli/app..."); const standaloneRoot = path.join(appDir, ".next", "standalone"); -if (!fs.existsSync(path.join(standaloneRoot, "server.js"))) { - console.error("❌ Next.js standalone build not found at .next/standalone/server.js"); +const standaloneApp = path.join(standaloneRoot, "app"); +if (!fs.existsSync(standaloneApp)) { + console.error("❌ Next.js standalone build not found at .next/standalone/app"); console.error("Make sure output: 'standalone' is set in next.config.js"); process.exit(1); } -copyRecursive(standaloneRoot, cliAppDir); +copyRecursive(standaloneApp, cliAppDir); + +// Copy traced node_modules from standalone root into CLI bundle +const standaloneNodeModules = path.join(standaloneRoot, "node_modules"); +if (fs.existsSync(standaloneNodeModules)) { + copyRecursive(standaloneNodeModules, path.join(cliAppDir, "node_modules")); +} console.log("✅ Copied standalone build\n"); // Step 3b: Ensure sql.js (pure JS fallback) bundled in app/cli/app/node_modules. diff --git a/next.config.mjs b/next.config.mjs index 98e2e52..0121ea3 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,16 +1,21 @@ import { fileURLToPath } from "node:url"; -import { dirname } from "node:path"; +import { dirname, join } from "node:path"; const projectRoot = dirname(fileURLToPath(import.meta.url)); +// CLI bundling needs workspace root so tracing includes hoisted node_modules (slim ~50MB). +// Docker / default uses projectRoot so server.js lands at /app/server.js (not nested). +const tracingRoot = process.env.NEXT_TRACING_ROOT_MODE === "workspace" + ? join(projectRoot, "..") + : projectRoot; /** @type {import('next').NextConfig} */ const nextConfig = { output: "standalone", serverExternalPackages: ["better-sqlite3", "sql.js", "node:sqlite", "bun:sqlite"], turbopack: { - root: projectRoot + root: tracingRoot }, - outputFileTracingRoot: projectRoot, + outputFileTracingRoot: tracingRoot, outputFileTracingExcludes: { "*": ["./gitbook/**/*"] }, diff --git a/package.json b/package.json index 62596dd..138d2e8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "9router-app", - "version": "0.4.38", + "version": "0.4.39", "description": "9Router web dashboard", "private": true, "scripts": {