Skip to content

CJS re-export regression with externalLiveBindings: false #5377

@yyx990803

Description

@yyx990803

Rollup Version

^4.9.3

Operating System (or Browser)

any

Node Version (if applicable)

No response

Link To Reproduction

https://rollupjs.org/repl/?version=4.9.6&shareable=JTdCJTIyZXhhbXBsZSUyMiUzQW51bGwlMkMlMjJtb2R1bGVzJTIyJTNBJTVCJTdCJTIyY29kZSUyMiUzQSUyMmV4cG9ydCUyMColMjBmcm9tJTIwJ3Z1ZSclMjIlMkMlMjJpc0VudHJ5JTIyJTNBdHJ1ZSUyQyUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiUyMm91dHB1dCUyMiUzQSU3QiUyMmV4dGVybmFsTGl2ZUJpbmRpbmdzJTIyJTNBdHJ1ZSUyQyUyMmZvcm1hdCUyMiUzQSUyMmNqcyUyMiU3RCUyQyUyMnRyZWVzaGFrZSUyMiUzQXRydWUlN0QlN0Q=

Expected Behaviour

Generated code can be used with named imports from es modules in Node.js.

Actual Behaviour

Code generated before #5313:

// out.js
const vue = require('vue');

Object.keys(vue).forEach(function (k) {
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) exports[k] = vue[k];
});

After #5313:

// out.js
const vue = require('vue');

Object.keys(vue).forEach(function (k) {
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) k === '__proto__' ? Object.defineProperty(exports, k, {
    enumerable: true,
    value: vue[k]
  }) : exports[k] = vue[k];
});

When imported from an es module, e.g.

// test.mjs
import { computed } from 'vue'
console.log(computed)

Code generated before #5313 is compatible with Node.js' cjs re-exports detection (via cjs-module-lexer), but code after is not, causing the esm usage to fail.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions