Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code splitting with default exports produces broken CJS output #2721

Closed
nullobject opened this issue Feb 26, 2019 · 3 comments · Fixed by #2727
Closed

Code splitting with default exports produces broken CJS output #2721

nullobject opened this issue Feb 26, 2019 · 3 comments · Fixed by #2727

Comments

@nullobject
Copy link

nullobject commented Feb 26, 2019

  • Rollup Version: 1.3.0
  • Operating System (or Browser): Mac OS Mojave
  • Node Version: 10.14.0

How Do We Reproduce?

Code splitting any modules with default exports will produce broken CJS output, even for very simple modules. I noticed the issue when reading this blog post by @lukastaegert.

Say we have two files:

// foo.js
export default 'hello'
// main.js
export { default as foo } from './foo'

When these files are bundled with code splitting we get:

// foo.js
module.exports = 'hello'
// main.js
var foo = require('./foo.js')
exports.foo = foo.default

But foo.default is undefined!

The blog post I mentioned earlier has a REPL which illustrates this issue. Just look at the CJS output and you'll see the export statements in main.js are broken.

Expected Behavior

// main.js
var foo = require('./foo.js');
exports.foo = foo;

Actual Behavior

// main.js
var foo = require('./foo.js');
exports.foo = foo.default;
@lukastaegert
Copy link
Member

Thanks for spotting this. Just some notes to myself or whoever fixes this (I hope to find time soon but cannot make promises about the next days):

  • we could just add the normal interop (not nice)
  • much better: we make sure the chunk has the correct exports mode and dynamically determine from there how to retrieve the default

@lukastaegert
Copy link
Member

Fix at #2727

@nullobject
Copy link
Author

Legend, thank you ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants