From 8374fc325bc6db032e479bd8b0ac015d0ae362ad Mon Sep 17 00:00:00 2001 From: minimus7 Date: Mon, 9 Nov 2026 12:18:13 -0600 Subject: [PATCH] Start: install when next is missing, not only when node_modules is A stopped first install left a half-full node_modules, so the next start skipped npm ci and failed with spawn node_modules/.bin/next ENOENT. Co-Authored-By: Claude Opus 5.5 --- scripts/start.mjs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/scripts/start.mjs b/scripts/start.mjs index 433f9ba..da7de78 100755 --- a/scripts/start.mjs +++ b/scripts/start.mjs @@ -16,7 +16,9 @@ if (Number(process.versions.node.split(".")[0]) < 20) { const win = process.platform === "win32"; const npm = (...args) => spawnSync("npm", args, { stdio: "inherit", shell: win }).status === 0; // npm ci installs exactly what the repo pins and leaves package-lock.json as it is (so `npm run update` stays clean). -if (!existsSync("node_modules") && !npm("ci") && !npm("install")) process.exit(1); +// Checks for next itself, not node_modules: a stopped first install leaves a half-full node_modules. +const nextBin = join("node_modules", ".bin", win ? "next.cmd" : "next"); +if (!existsSync(nextBin) && !npm("ci") && !npm("install")) process.exit(1); const env = {}; for (const f of [".env", ".env.local"]) { @@ -52,7 +54,7 @@ const built = existsSync(".next/BUILD_ID") ? statSync(".next/BUILD_ID").mtimeMs const stale = Math.max(...["src", "public", "package-lock.json", "next.config.ts", ".env", ".env.local"].map(newest)) > built; if (ready && !stale) console.log("Nothing changed since the last build: starting it."); if (ready && stale && !npm("run", "build")) process.exit(1); -const next = join("node_modules", ".bin", win ? "next.cmd" : "next"); +const next = nextBin; // Listens on this computer only, which is what makes saving keys from the page safe (writeGate checks the rest). const args = ready ? ["start", "-H", "127.0.0.1", "-p", String(port)] : ["dev", "--turbopack", "-H", "127.0.0.1", "-p", String(port)]; const server = spawn(next, args, { stdio: "inherit", shell: win, env: { ...process.env, ALLOW_SETUP_WRITES: "1" } });