-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
CDN version of the plain (esm) chart.js cannot be imported? #11592
Comments
May be similar to #10915. |
Just found the same issue and, following the issue mentioned above, solved it by linking the version with "umd" in its name. For example, |
@mukham12 that's a server-side issue though, so probably caused by something else. @hfingler that's not really a solution if you're writing modern JS with ES modules, though. UMD exports are incompatible with ESM, You just end up importing a module that has no exports, which means you still can't do anything. (open dev tools, and run |
Good point. I'm working on a small, simple project, so that was enough for me. |
Same, but I'm only working in modern JS these days (both in the browser and in Node), so it has to be ESM-loadable. |
This does not work nether, even with a very simple example page, basically slightly varied from the first step in the tutorial. I am using Django and had no problem with the version 3. I would prefer not to get back to this version for the new project. Now I get (the server from the browsers error message is my static files server, I have no idea, why/how Firefox looks there):
|
@ludgerh that's a different version with a different problem, though. I've updated the title, but for this particular it'll be better to delete those comments and file a separate one. |
Imagine you are selecting a JS lib do charting for your project and try to run some simple tests in the browser. This bug is a complete dealbreaker. "Moving on to then next lib ... ". Surly hope this is fixed soon. |
I ran into the same issue, which seems to be that the documentation and the CDN deployed scripts suffer from some mismatch. My main "use case" here is that I was trying to avoid having a |
I'm with the same problem in Vanilla JavaScritp... The unique solution was to use the CDN from the example in the documentation. Without Typescript or imports, only the link of CDN in the script tag. |
@Zafkiel45 i was running through the same issue al i did was download the source files then have ascript tag in my html before i imported my other js script so teh variable Chart will alwasy be got from the script above it i hope others wi be alble to fix it the sae way |
Chart.js feels more than a little out of step with modern JS if I can't import it from a ESM source, the entire ecosystem of JS is moving on from UMD Having to using script tags in the HTML is a massive step backwards |
Using script tags is perfectly fine (and actually improves performance because you're letting the browser take care of caching. The biggest crime against getting the best performance is bundling) but the lack of a working library is a bit of a problem. |
I had the same issue I used script tags now when u want to use it in the
JavaScript use the window object window.chartjs it will be available on
the window object
…On Mon, 11 Nov 2024, 05:38 Pomax, ***@***.***> wrote:
Using script tags is perfectly fine (and actually *improves* performance
because you're letting the browser take care of caching. The biggest crime
against getting the best performance is bundling). But the lack of a
working library is a bit of a problem.
—
Reply to this email directly, view it on GitHub
<#11592 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AFRDI3B4AUOWZ5VOLCUCB7L2AAKDVAVCNFSM6AAAAAA7YFE6N6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINRXGEYTSMZYHE>
.
You are receiving this because you commented.Message ID: <chartjs/Chart.
***@***.***>
|
Keep in mind not everyone uses Node-related tools. So some of us just need a working script we can load from a CDN. |
I'm not using Node, I'm trying to use Chart.js in a vanilla JS project using ESM and modules, i.e. The ESM CSN version available at this URL |
<script src="~/lib/chrt443/chart.umd.js"></script>
load this in your index html that is after downaoding the files from the repo then after it will load the chartjs ina the dom then after do soething like this |
@ferouzkassim please read the first comment, which clearly explains that your comment shouldn't be in this thread because it's specifically about loading Chart.js, the plain ESM version, from CDN. The code you're showing is neither of those things, and it would be much more helpful if you deleted it again. |
I was able to make ChartJS work in ESM, by loading it from https://esm.sh instead. I've also made a minimal example in https://stackblitz.com/edit/vitejs-vite-1jfgup?file=index.html The general idea is to:
Edit: for the sake of brevity...
|
That is an excellent workaround for now, thank you for posting that. |
I'll second that! I just tried this workaround, using esm.sh and it's working great in my mjs code, and thanks for the working example as I would have never found the need to call Awesome thank you |
@benc-uk that action wasn't really clear to me either, as it was implicitly handled in Lines 1 to 3 in bb82c8f
When I explored proper tree-shaking with esm.sh, that's when I found #10163 , which shows how registration works 🎉 |
Expected behavior
I expected to be able to import
Chart
from the CDN url https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.0/chart.jsCurrent behavior
Uncaught (in promise) TypeError: The specifier “@kurkle/color” was a bare specifier, but was not remapped to anything. Relative module specifiers must start with “./”, “../” or “/”.
Reproducible sample
no full example necessary
Optional extra steps/info to reproduce
Open a dev console and run
import("https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.0/chart.js").then(lib => console.log(lib))
. It'll error out.Possible solution
No response
Context
https://www.chartjs.org/docs/latest/getting-started/installation.html suggests that if you don't want to use npm (for instance, you're working on a "classic" web page that's just static HTML, CSS, and JS) you can use one of several CDNs with CDNJS listed as first option, so that's what folks will most likely go for.
https://www.chartjs.org/docs/latest/getting-started/integration.html then teaches people that it's an ES module so
import
works out of the box, and so we run into a problem because instead it errors out.chart.js version
4.4.0
Browser name and version
n/a
Link to your project
n/a
The text was updated successfully, but these errors were encountered: