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

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.

Author: Fantashit

1 thought on “Webpack 2 + System.import: default export has to be read with .default

Comments are closed.