mirror of
https://github.com/oven-sh/bun
synced 2026-02-26 19:47:19 +01:00
## Summary - When `require()` loads an ESM module (`.mjs`) that throws during evaluation, the module was removed from `requireMap` but left in the ESM registry (`Loader.registry`) in a partially-initialized state - A subsequent `import()` of the same module would find this corrupt entry and throw `ReferenceError: Cannot access 'foo' before initialization` instead of re-throwing the original evaluation error - Fix by also deleting the module from `Loader.registry` in both `overridableRequire` and `requireESMFromHijackedExtension` when ESM evaluation fails, allowing `import()` to re-evaluate from scratch Closes #27287 ## Test plan - [x] Added regression test in `test/regression/issue/27287.test.ts` - [x] Verified test fails with system bun (`USE_SYSTEM_BUN=1`) - [x] Verified test passes with `bun bd test` - [x] Manual verification: `require()` correctly throws original error, `import()` now re-throws the same error instead of `ReferenceError` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Bot <claude-bot@bun.sh> Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Alistair Smith <alistair@anthropic.com>