chartjs / chartjs/Chart.js

CDN version of the plain (esm) chart.js cannot be imported?

Open
#11,592 25 comments 10 reactions 0 assignees View on GitHub
type: bug
Dominant language
JavaScript
Stars
67.7k
Forks
11.9k
Avg merge
7h 39m
Merged PRs (30d)
5

Description

### 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.js

### Current 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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.