3 ms·
There's an explosion of module types. Node has cjs and esm, Browser has legacy (create sub-objects in the global or window object) and esm. I tried to write a
by _nalply 3y ago
There's an explosion of module types.
Node has cjs and esm, Browser has legacy (create sub-objects in the global or window object) and esm.
I tried to write a polyglot, but was not successful. https://stackoverflow.com/questions/48396968/72314371 https://stackoverflow.com/questions/48396968/72314371 proposes a clever polyglot exploiting that await is parsed differently at the top level when in esm or not. However this doesn't help, because import and export keywords always fail hard (not catchable by try-catch) and eval (yuck!) doesn't help because inside eval your are legacy.
So you have to bundle if you want to provide for everybody... (shrugs)