Skip to content

reexports detection incompatible with output from Rollup@^2.39.0 #38

@yyx990803

Description

@yyx990803

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions