diff --git a/test/js/bun/resolve/resolve-require-nonexistent-no-crash.test.ts b/test/js/bun/resolve/resolve-require-nonexistent-no-crash.test.ts new file mode 100644 index 000000000000..bba28c4f2c34 --- /dev/null +++ b/test/js/bun/resolve/resolve-require-nonexistent-no-crash.test.ts @@ -0,0 +1,18 @@ +import { expect, test } from "bun:test"; +import { bunEnv, bunExe, tempDir } from "harness"; + +// Regression test: require() of a nonexistent package should not crash +// due to PackageManager.log pointing at a stale stack-allocated Log +// when the resolve path triggers auto-install network activity. +test("require of nonexistent module does not crash", async () => { + using installDir = tempDir("resolve-require-nonexistent-no-crash-", {}); + await using proc = Bun.spawn({ + cmd: [bunExe(), "-e", `try { require("nonexistent-pkg-38391"); } catch (e) {}`], + env: { ...bunEnv, BUN_INSTALL_GLOBAL_DIR: String(installDir) }, + stderr: "inherit", + }); + + const exitCode = await proc.exited; + + expect(exitCode).toBe(0); +});