question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Support __esModule marker from babel&co.

See original GitHub issue

A lot of code on npm is ESM code that was rewritten by babel or others to be compatible with CommonJS. Not all packages publish ESM+CommonJS. The code will contain a special __esModule marker on the exports which Closure currently does not support. webpack and others use this to enable a smoother interop between ESM/CommonJS.

Example:

export let foo = 1;

is rewritten to

"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
var foo = exports.foo = 1;

In webpack you can now import { foo } from "..."; just fine since they detect the __esModule marker (in non-strict mode).

Currently when using the rewriting facilities from Closure prevent this from working at all since it treats the code as CommonJS and rewrites everything to .default meaning that you can only do import X from "..."; and then X.foo. Unfortunately this breaks many npm packages that seem to rely on the webpack style interop.

I’ll try to create a proper reproducible example with some example npm packages but wanted to discuss this first. Maybe this has come up internally or some decision to not support this was already made.

webpack has documented there behaviour here and the case that is currently problematic is A2. (The document uses dynamic import() but the static import ...; acts the same).

Thoughts?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:10

github_iconTop GitHub Comments

1reaction
ChadKillingsworthcommented, Jun 22, 2018

I just encountered this myself - and it wasn’t pleasant to work around.

I think a path forward here my be to recognize these modules and switch the exports back to ES module export statements.

0reactions
garrett-hoppercommented, Jun 30, 2018

Thanks, @ChadKillingsworth! After building the closure compiler from source and then building the clojurescript compiler to use it, everything seems to be working as expected. 😃 Thanks for all your help too, @thheller!

Read more comments on GitHub >

github_iconTop Results From Across the Web

No results found

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found