esm.sh icon indicating copy to clipboard operation
esm.sh copied to clipboard

Code transformation breaks package?

Open trusktr opened this issue 2 years ago • 4 comments

Here's a live example:

https://codepen.io/trusktr/pen/WNPgwNZ/bbce4b6d555ab200054bed163ad6e0a7?editors=1000

The error:

Uncaught Error: Unrecognized extension value in extension set ([object Object]). This sometimes happens because multiple instances of @codemirror/state are loaded, breaking instanceof checks.

I'm familiar with the error, but it seems like the code transformation is changing something to be not what it should be.

This example works fine locally where the only difference is that the import at the top of the HTML is importing local vanilla ES Modules (and the top of the HTML also has a needed importmap):

https://github.com/lume/live-code/blob/bbef27fe581d9a29e769c93e26ad7fcd8c05df64/examples/index.html#L53

Other than that, its all the same code with the main difference being that the pen is importing transformed code from esm.sh.

trusktr avatar Nov 28 '23 22:11 trusktr

I got the example mostly working without code transformations using

  • an importmap
  • * in front of all package names
  • and ?raw option for all URLs

https://codepen.io/trusktr/pen/YzBOqpq/50658233b7a3430b9cad10fe34baca41?editors=1000

Now there are no more runtime errors, but some of the editor examples are still not working quite right. 🤔

trusktr avatar Nov 28 '23 22:11 trusktr

UPDATE: looks like in that last example esm.sh still does some code transformations for some files. For example, I see it loads files from @lume/element minified (and maybe broken).

I can't get it to work perfectly like the local example because I can't get the code to be fully raw.

trusktr avatar Nov 28 '23 22:11 trusktr

I highly recommend making esm.sh by default not transform any code, no minfication, no bundling, no anything, just plain raw code as-is with importmaps (the best vanilla ESM CDN), and let people opt into optimizations that might break things.

Better if everything just works out of the box.

As of now, esm.sh by default has many many issues due to all the things it does out of the box, and this is a high maintanenance burden that does not seem fixable any time soon.

Web developers need an ESM CDN that works perfectly out of the box (even if that's not the most optimized possible). The best way to do that is serving their code as-is.

trusktr avatar Nov 28 '23 23:11 trusktr