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

Webpack 2 + System.import: default export has to be read with .default #2188

Closed
Jessidhia opened this issue Mar 15, 2016 · 6 comments
Closed

Comments

@Jessidhia
Copy link
Member

Snippet demonstrating the issue:

// test.js
export default class Test {}

// index.js (with proper runtime available)
System.import('./test').then(Test => {
  new Test() // error! must use new Test.default()
})

The following code gets generated in webpack's chunk containing test.js:

/* harmony default export */ exports["default"] = Test;

This behaves differently from when you use import Test from './test', as when you use such a static import you can then call new Test() instead of having to call new Test.default().

I also considered this might be an issue with babel transforms, but as it is getting emitted as a /* harmony default export */, I don't believe babel is transforming the export. I am using the es2015-webpack preset to preserve harmony imports/exports.

Not sure if this a webpack 2 bug or just a documentation issue.

@Jessidhia
Copy link
Member Author

Hm, I just noticed that this basically has the same behavior as import * as Test from './test'. In this case, I would still have to access Test.default to get at the default export.

Thus, I suppose this is only a documentation (or expectation) issue.

@helloyou2012
Copy link

@Kovensky , I use this plugin to solve this problem: https://github.com/59naga/babel-plugin-add-module-exports

@sokra
Copy link
Member

sokra commented Mar 30, 2016

Not sure if this a webpack 2 bug or just a documentation issue.

Thus, I suppose this is only a documentation (or expectation) issue.

Yep, working as intended.

@sokra
Copy link
Member

sokra commented Mar 30, 2016

@Kovensky , I use this plugin to solve this problem: https://github.com/59naga/babel-plugin-add-module-exports

I don't recommend this. babel had good reasons for no longer doing so.

@pksjce
Copy link

pksjce commented Sep 7, 2016

This issue was moved to webpack/webpack.js.org#122

@bebraw bebraw closed this as completed Sep 7, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants