Since Rollup@^2.39.0, the cjs output for re-exports has changed a bit:
Object.keys(foo).forEach(function (k) {
- if (k !== 'default') Object.defineProperty(exports, k, {
+ if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
enumerable: true,
get: function () {
return foo[k];
}
});
});
The extra hasOwnProperty check breaks re-exports detection of cjs-module-lexer.
The implication of this:
cjs-module-lexer is used in Node.js' ESM mode to detect named exports compatibility for CJS modules
- Many packages use Rollup to bundle for CJS distribution (e.g. Vue 3.0)
- Previously, these packages "just worked" for named imports from Node.js in ESM mode because
cjs-module-lexer was able to detect the re-exports
- After upgrading Rollup to 2.39.0, the named imports are broken.
Reproduction
https://github.com/yyx990803/cjs-module-lexer-rollup-reexports
- Install deps
npm run build (which builds src/index.js with Rollup to out.js)
node lex.js (which runs cjs-module-lexer on out.js)
Since Rollup@^2.39.0, the cjs output for re-exports has changed a bit:
Object.keys(foo).forEach(function (k) { - if (k !== 'default') Object.defineProperty(exports, k, { + if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, { enumerable: true, get: function () { return foo[k]; } }); });The extra
hasOwnPropertycheck breaks re-exports detection ofcjs-module-lexer.The implication of this:
cjs-module-lexeris used in Node.js' ESM mode to detect named exports compatibility for CJS modulescjs-module-lexerwas able to detect the re-exportsReproduction
https://github.com/yyx990803/cjs-module-lexer-rollup-reexports
npm run build(which buildssrc/index.jswith Rollup toout.js)node lex.js(which runscjs-module-lexeronout.js)