From 195c23dbb29e815bff6d3fe888e057d701930de5 Mon Sep 17 00:00:00 2001 From: Askhz <1361267452@qq.com> Date: Thu, 14 May 2026 17:00:43 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E7=BC=96=E8=AF=91=E5=90=8E=E4=BA=8C?= =?UTF-8?q?=E8=BF=9B=E5=88=B6=20serve=20=E5=AD=90=E8=BF=9B=E7=A8=8B=20cras?= =?UTF-8?q?h=20=E6=8A=A5=20unknown=20option=20--feature?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit getScriptArgsForChild() 无法正确识别编译后的二进制:argv[1] 仍为原始入口 路径(如 src/entrypoints/cli.tsx),被误判为脚本模式,导致 saveChildSpawnPrefix() 生成 --feature Bun 专有参数传给子进程,子进程不识别直接 crash。 修复:在所有判断之前增加 execPath basename 检查,非 bun/node 的可执行文件 直接视为编译二进制,返回空数组。 Co-Authored-By: CoStrict-DeepSeek-V4-Pro --- src/server/childSpawn.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/server/childSpawn.ts b/src/server/childSpawn.ts index 9ef52e639..343624ddc 100644 --- a/src/server/childSpawn.ts +++ b/src/server/childSpawn.ts @@ -1,3 +1,5 @@ +import { basename } from 'path' + export const INIT_TIMEOUT_MS = (() => { const raw = Number(process.env.CSC_SERVE_INIT_TIMEOUT_MS) return Number.isFinite(raw) && raw > 0 ? raw : 120000 @@ -6,10 +8,18 @@ export const INIT_TIMEOUT_MS = (() => { export function getScriptArgsForChild(): string[] { const argv1 = process.argv[1] if (!argv1) return [] + // If the executable is not bun/node, we're in a compiled standalone binary. + // In compiled mode, argv[1] may be the original entrypoint path (e.g. + // "src/entrypoints/cli.tsx") which looks like a script — prevent that. + const execBase = basename(process.execPath) + if (!/^(bun|node)/i.test(execBase)) return [] // Bun standalone executable embeds a virtual snapshot path like "B:/~BUN/root/cli.js". // This is not a real file on disk — skip it so the child process (the same exe) // is not launched with a bogus script argument. if (argv1.startsWith('B:/~BUN/') || argv1.startsWith('/snapshot/')) return [] + // When running as a compiled standalone binary (./csc), argv[1] is the binary + // itself — same as execPath. Do not treat it as a script file. + if (argv1 === process.execPath) return [] if (argv1.endsWith('.ts') || argv1.endsWith('.tsx') || argv1.includes('/') || argv1.includes('\\')) { return [argv1] } @@ -58,4 +68,4 @@ export function loadChildSpawnPrefix(): { execPath: string; scriptArgs: string[] } catch { return null } -} +} \ No newline at end of file