ES6 modules compatibility with commonjs

I’m submitting a bug report

Webpack version:
2.1.0beta-21.0

Please tell us about your environment:
OSX 10.x

Can someone explain this to me. I am writing a library with target: "node" , libraryTarget: "commonjs2" and library: "jwt".

From within my src/index.js file, I have multiple exports:

export { a, b, c};

export default (d) => "e";

export const f = "g";

I consume this library in my project like:

import jwt, { a, b, c, f } from "jwt";

However, jwt is set to the entire module.exports object rather than module.exports["default"]. Is this expected behavior or am I doing something wrong?

Note: I am not using Babel for any transpiling. This code is meant for node >= 6.4.0, so it can’t be a Babel issue.

Author: Fantashit

2 thoughts on “ES6 modules compatibility with commonjs

  1. __esModule = true need to be set only on library export. It need to be set on the exports of the entry module. Inner modules don’t need __esModule, it’s just a babel hack.

    Workaround:

    export const __esModule = true in entry module.

  2. I added a new libararyTarget "commonjs-module which represents a harmony/ES6 module which is wrapped via CommonJs (__esModule).

Comments are closed.