Skip to content

named exports being stripped with dynamic imports #5975

@danielroe

Description

@danielroe

Rollup Version

4.41.1

Operating System (or Browser)

MacOS

Node Version (if applicable)

No response

Link To Reproduction

https://rollupjs.org/repl/?version=4.41.1&shareable=JTdCJTIyZXhhbXBsZSUyMiUzQW51bGwlMkMlMjJtb2R1bGVzJTIyJTNBJTVCJTdCJTIyY29kZSUyMiUzQSUyMmltcG9ydCglNUMlMjIuJTJGcm9vdC5qcyU1QyUyMiklNUNuJTIwJTIwLnRoZW4oZnVuY3Rpb24obW9kKSUyMCU3QiU1Q24lMjAlMjAlMjAlMjByZXR1cm4lMjBtb2QubW9kJTNCJTVDbiUyMCUyMCU3RCklNUNuJTIwJTIwLnRoZW4oKG0pJTIwJTNEJTNFJTIwbS5kZWZhdWx0JTIwJTdDJTdDJTIwbSklMjIlMkMlMjJpc0VudHJ5JTIyJTNBdHJ1ZSUyQyUyMm5hbWUlMjIlM0ElMjJtYWluLmpzJTIyJTdEJTJDJTdCJTIyY29kZSUyMiUzQSUyMmNvbnN0JTIwZGVmYXVsdEV4cG9ydCUyMCUzRCUyMCdkZWZhdWx0RXhwb3J0JyU1Q25jb25zdCUyMG5hbWVkRXhwb3J0JTIwJTNEJTIwJ25hbWVkRXhwb3J0JyU1Q24lNUNuY29uc3QlMjBtb2QlMjAlM0QlMjAlN0IlNUNuJTIwJTIwZGVmYXVsdCUzQSUyMGRlZmF1bHRFeHBvcnQlNUNuJTdEJTVDbiU1Q25leHBvcnQlMjAlN0IlNUNuJTIwJTIwbW9kJTJDJTVDbiUyMCUyMG5hbWVkRXhwb3J0JTVDbiU3RCUzQiUyMiUyQyUyMmlzRW50cnklMjIlM0FmYWxzZSUyQyUyMm5hbWUlMjIlM0ElMjJyb290LmpzJTIyJTdEJTVEJTJDJTIyb3B0aW9ucyUyMiUzQSU3QiU3RCU3RA%3D%3D

Expected Behaviour

related: nuxt/nuxt#32175

we have a two stage build, and the first rollup build produces code like this (which I've cleaned up for the reproduction):

// entry
import("./root.js")
  .then(function(mod) {
    return mod.mod;
  })
  .then((m) => m.default || m)

// root.js
const defaultExport = 'defaultExport'
const namedExport = 'namedExport'

const mod = {
  default: defaultExport
}

export {
  mod,
  namedExport
};

I would expect the default export to be preserved.

Note that this is only with inline function vs arrow function. .then(mod => mod.mod) works fine

Actual Behaviour

Upon being transformed a second time by rollup, the export is annulled:

Promise.resolve().then(function () { return root; })
  .then(function(mod) {
    return mod.mod;
  })
  .then((m) => m.default || m);

var root = /*#__PURE__*/Object.freeze({
  __proto__: null
});

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions