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

Chartjs .js and .cjs are both imported when using chartjs-plugin-datalabels #400

Open
AoDev opened this issue Nov 3, 2023 · 0 comments
Open

Comments

@AoDev
Copy link

AoDev commented Nov 3, 2023

Summary

Both the .js and .cjs versions of chart.js are imported and bundled when using this plugin.

Libs versions

  • chart.js: 4.4.0
  • chartjs-plugin-datalabels: 2.2.0
  • react-chartjs-2: 5.2.0
  • webpack: 5

Description

Both the .js and .cjs versions of chart.js are bundled in my react / typescript app when I use chartjs-plugin-datalabels.
The app is bundled with Webpack 5. I verified that this issue does not happen if I don't import it.

The plugin is imported like so:

import {Chart as ChartJS} from 'chart.js'
import ChartDataLabels from 'chartjs-plugin-datalabels'

ChartJS.register(ChartDataLabels)

Note that it is specifically the register(...) line that causes the problem.
If I import the plugin but not register it, there is no duplication

Further investigation

I don't know if the problem is chart.js or datalabels so I decided to test with another plugin.

I tried with chartjs-plugin-autocolors and can confirm the duplication issue does not happen.

So, at the moment I decided to write the issue here.

Screenshots

Checked with the BundleAnalyzerPlugin

without chartjs-plugin-datalabels with chartjs-plugin-datalabels
image image
only .js included both .cjs & .js included
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant