Repository navigation
Replies: 1 comment
|
Confirmed with The cause is in I've opened a PR with the fix: #2045. It sets Until that's released, either of these avoids // keep the module.exports reference, without replacing the object
Object.assign(module.exports, { seenByB: b.seen });
// or assign properties
exports.seenByB = b.seen;Both print |
Uh oh!
There was an error while loading. Please reload this page.
In
@rollup/plugin-commonjs29.0.3 (withrollup4.68.0), a module with a top-levelmodule.exports = ...assignment and no othermoduleorexportsreferences 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()returnsundefinedinstead of the initial{}exports object.Bundling
entry.jswith@rollup/plugin-commonjs(defaultstrictRequires: trueor'auto') and running the output prints{ seenByB: 'undefined' }. Runningnode entry.jsdirectly prints{ seenByB: 'object' }, as required by Node's CommonJS cycle semantics (an unfinished module returns its initial{}exports object).The same uninitialized
varalso causes top-levelthisaccesses beforemodule.exports = ...(e.g.this.x = 1; module.exports = { y: 2 };) to throwTypeError: Cannot set properties of undefined.Credit: https://ucsbplse.github.io/
All reactions