Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The library does not work correctly when used via esm-cdn #1797

Open
Qsppl opened this issue Dec 2, 2024 · 5 comments
Open

The library does not work correctly when used via esm-cdn #1797

Qsppl opened this issue Dec 2, 2024 · 5 comments
Labels

Comments

@Qsppl
Copy link

Qsppl commented Dec 2, 2024

The library does not work correctly when used via esm-cdn

Expected

See Donut Chart - Working example

image

Observed

See Donut Chart - Non-working example (deprecated)
See Donut Chart - Non-working example

image

Additional info

I have raised a related issue in the esm.sh repository esm-dev/esm.sh#934

Could you share more details for ESM.SH developers? What exactly was assembled incorrectly? Is there a bug somewhere in the code or is some specific dependency not working correctly?

I also see that this issue has already been raised previously in #1564, but I was unable to continue that discussion.

@Pauan
Copy link
Collaborator

Pauan commented Dec 6, 2024

I've looked at the build output of esm.sh... I did notice a few weird things.

For some strange reason it uses .mjs for most of the files, but for Animated and percent it uses .js

I also noticed that it's exporting twice from Animated.js:

/* esm.sh - @amcharts/[email protected]/themes/Animated */
export * from "/v135/@amcharts/[email protected]/es2022/themes/Animated.js";
export { default } from "/v135/@amcharts/[email protected]/es2022/themes/Animated.js";

It shouldn't need the second export { default } from "...";

And it's importing tslib and d3-shape multiple times, when it shouldn't:

/* esm.sh - @amcharts/[email protected] */
import "/v135/[email protected]/es2022/tslib.mjs";
import "/v135/[email protected]/es2022/svg-arc-to-cubic-bezier.mjs";
import "/v135/[email protected]/es2022/d3-shape.mjs";
export * from "/v135/@amcharts/[email protected]/es2022/amcharts5.mjs";
/* esm.sh - @amcharts/[email protected]/percent */
import "/v135/[email protected]/es2022/tslib.mjs";
import "/v135/[email protected]/es2022/d3-shape.mjs";
export * from "/v135/@amcharts/[email protected]/es2022/percent.js";

The above things are pretty minor, but I found a major bug with esm.sh.

I noticed that it's not handling cross-file imports properly. The percent.js and Animated.js files are supposed to be importing things from amcharts5.mjs... but they aren't. There's no imports at all.

So it seems to be splitting each file into separate unrelated chunks, instead of sharing a single chunk.

@Qsppl
Copy link
Author

Qsppl commented Dec 6, 2024

Thank you very much for the work done, I will double-check each error and open relevant issues in the ESM.SH repository.

Please report if you find any more errors.

I will report progress on the issues raised in this thread so that you can return to this issue at a later date.

@Qsppl
Copy link
Author

Qsppl commented Dec 6, 2024

In the broken chart example, I accidentally used multiple versions of AMCharts.

image

In the past, this might have prevented you from finding the real problem.

I have fixed this problem and updated the example link in the first post of the thread.

image

Just in case, I’ll write down here a link to the previous example with importing several versions of AMCharts, so that you can compare the examples if necessary: https://codepen.io/qsppl/pen/KwPPLaa

@Qsppl
Copy link
Author

Qsppl commented Dec 6, 2024

I noticed that it's not handling cross-file imports properly. The percent.js and Animated.js files are supposed to be importing things from amcharts5.mjs... but they aren't. There's no imports at all.

So it seems to be splitting each file into separate unrelated chunks, instead of sharing a single chunk.

Here in the file five imports of different modules of one project are performed:

image

But it seems that ESM.SH returned not five modules of one project, but five differently builded projects.

image

Accordingly, all variables exported from modules are their own for each import.

This must be the problem I was looking for. Thank you very much.

@Pauan
Copy link
Collaborator

Pauan commented Dec 10, 2024

But it seems that ESM.SH returned not five modules of one project, but five differently builded projects.

Yes, that's what I meant when I said that it's building multiple chunks instead of sharing a single chunk.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants