esm-dev / esm.sh

A fast, smart, & global CDN for modern(es2015+) web development.
https://esm.sh
MIT License
3.07k stars 147 forks source link

Failed to set `@use-gesture/core/action` as external dependency #832

Open svnhub opened 4 months ago

svnhub commented 4 months ago

Failing module

https://esm.sh/@use-gesture/core@10.3.1/ accidentally bundles actions.js from https://esm.sh/@use-gesture/core@10.3.1/actions which means that variables set on the imported actions module are not visible inside the bundled version of it when seen from core.

Using https://esm.sh/@use-gesture/core@10.3.1/?external=@use-gesture/core/actions or https://esm.sh/*@use-gesture/core@10.3.1 does not fix this.

Using ?no-bundle it is clear that core imports https://esm.sh/v135/@use-gesture/core@10.3.1/es2022/dist/actions-fe213e88.esm.js which is a minified version of @use-gesture/core/actions an hence even without bundling it is not possible to share variables since the source is different and when loaded it will end up in a different module instance.

Additional info

svnhub commented 4 months ago

Just verified the bug by building a working version locally where both @use-gesture/core and @use-gesture/core/actions reference the same external actions-xxxxxxxxx.esm.js module file.

So to simplify: The issue is that @use-gesture/core doesn't consider actions.js to be part of @use-gesture/core/actions but instead part of itself and by default the bundler inlines the code from it regardless of whether it was added as external to the esm.sh CDN URL or not. When using both @use-gesture/core and @use-gesture/core/actions in your app you then end up with two versions of actions.js - one inlined in core and one as module, causing the app to break.

ije commented 4 months ago
Screenshot 2024-05-17 at 18 27 03

i just found there is a package.json in the actions directory, the current server can't not handle it correctly, next version this will be fixed