fix(cli): detect bun: protocol imports and re-exec under Bun

Catch ERR_UNSUPPORTED_ESM_URL_SCHEME with bun: protocol in addition
to ReferenceError "Bun is not defined" when deciding to re-exec.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Cameron Pak
2026-03-07 10:02:16 -06:00
parent 45cf746855
commit 44d7c092f8
+5 -4
View File
@@ -179,10 +179,11 @@ export async function makeAppFromEnv(options: Partial<RunOptions> = {}) {
try {
const config = await loadConfigFile(configFilePath);
app = await makeConfigApp(config, options.server);
} catch (e) {
if (e instanceof ReferenceError && /\bBun\b.*not defined/.test(e.message)) {
reexecUnderBun();
}
} catch (e: any) {
const needsBun =
(e instanceof ReferenceError && /\bBun\b.*not defined/.test(e.message)) ||
(e?.code === "ERR_UNSUPPORTED_ESM_URL_SCHEME" && /bun:/.test(e.message));
if (needsBun) reexecUnderBun();
console.error("Failed to load config:", e);
process.exit(1);
}