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
{{ message }}
Repository navigation
@rollup/plugin-commonjs: circular require receives undefined instead of {} before module.exports = #2042
When a CommonJS module with a top-level module.exports = ... assignment is required back in a circular dependency before that assignment executes, require() should return the module's initial {} exports object, matching Node's CommonJS semantics (printing { seenByB: 'object' } in the reproduction below). Similarly, top-level this before module.exports = ... should refer to that initial {} object.
Actual Behavior
A module with a top-level module.exports = ... assignment and no other module or exports references leaves its exports variable uninitialized (var a;) until the assignment executes. If another module requires it back in a cycle before that assignment runs, require() returns undefined instead of {} (printing { seenByB: 'undefined' } in the reproduction below).
The same uninitialized var also causes top-level this accesses before module.exports = ... (e.g. this.x = 1; module.exports = { y: 2 };) to throw TypeError: Cannot set properties of undefined.
Bundling entry.js with @rollup/plugin-commonjs (default strictRequires: true or 'auto') and running the output prints { seenByB: 'undefined' }, whereas running node entry.js directly prints { seenByB: 'object' }.
Activity