You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Found this issue while attempting to switch Electron core from webpack -> esbuild. Claude identified the underlying issue and I manually verified. This issue and the PR that will follow both used AI assistance (via claude code)
When a bundled CJS-shaped file calls require() on a bundled ESM-shaped module, esbuild emits (init_foo(), __toCommonJS(foo_exports)). Since f4ff26d (0.14.27), __toCommonJS allocates a fresh wrapper on every call, so two require() calls for the same module return different objects.
This diverges from Node's CJS semantics (cached module.exports), webpack's __webpack_require__ cache, and esbuild ≤ 0.14.26 (which memoized via WeakMap). The removal commit calls the cache "unnecessary", which is true for the entry-point module.exports = __toCommonJS(...) use, but not for inline require() of a bundled ESM module.
Real-world impact: code that aliases two specifiers to the same module (e.g. exposing 'timers' and 'node:timers' from a sandbox require shim) or that registers state on require('foo') and reads it back via a second require('foo') silently breaks.
Note
Found this issue while attempting to switch Electron core from webpack -> esbuild. Claude identified the underlying issue and I manually verified. This issue and the PR that will follow both used AI assistance (via claude code)
When a bundled CJS-shaped file calls
require()on a bundled ESM-shaped module, esbuild emits(init_foo(), __toCommonJS(foo_exports)). Since f4ff26d (0.14.27),__toCommonJSallocates a fresh wrapper on every call, so tworequire()calls for the same module return different objects.This diverges from Node's CJS semantics (cached
module.exports), webpack's__webpack_require__cache, and esbuild ≤ 0.14.26 (which memoized via WeakMap). The removal commit calls the cache "unnecessary", which is true for the entry-pointmodule.exports = __toCommonJS(...)use, but not for inlinerequire()of a bundled ESM module.Repro (playground):
Expected:
trueReal-world impact: code that aliases two specifiers to the same module (e.g. exposing
'timers'and'node:timers'from a sandboxrequireshim) or that registers state onrequire('foo')and reads it back via a secondrequire('foo')silently breaks.