chartjs / chartjs-plugin-datalabels

Chart.js plugin to display labels on data elements
https://chartjs-plugin-datalabels.netlify.app
MIT License
874 stars 473 forks source link

Error running the latest chartjs-plugin-datalabels with NextJS #350

Open DecadentIpsum opened 1 year ago

DecadentIpsum commented 1 year ago

Hello,

I am developing a NextJS site and I installed the latest "chartjs-plugin-datalabels".

When I am running my project I got the following error:

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './helpers' is not defined by "exports" in /Users/zaralisandreas/Desktop/Projects/odify/node_modules/chart.js/package.json

I am using Node v18.12.1 and Chart.js 4.0.1.

Any ideas?

I really appreciate any help you can provide.

dqve commented 1 year ago

Same issues here.

DecadentIpsum commented 1 year ago

@simonbrunel any ideas? :)

Igosuki commented 1 year ago

This package uses chart.js 3.0

simonbrunel commented 1 year ago

@DecadentIpsum Sorry, no idea. Do you use any other Chart.js plugins that actually work with your setup?

You could try with the new plugin version 2.2.0, however I don't think it will change anything.

If you need people to help you with your issue, you will have to provide a way to reproduce it.

ignaciodiazb commented 1 year ago

Same problem here. I deleted node_modules, yarn.lock and even cleared cache before installing dependencies again but nothing worked.

stockiNail commented 1 year ago

@simonbrunel I think the plugin must be defined as "module" and defines the exports. See https://github.com/chartjs/chartjs-plugin-annotation/pull/815 and other plugins (gradient https://github.com/kurkle/chartjs-plugin-gradient/blob/master/package.json)

NotTimTam commented 1 year ago

Same here, no other plugins. Just the latest version of both packages.

Screenshot 2022-12-12 at 1 13 41 PM
simonbrunel commented 1 year ago

Thanks @stockiNail for the info. While you are probably right, I don't want to blindly push these changes but first would like to experiment with the reported cases. Also, we need to be sure that it doesn't break existing integrations since changing type: "module" may have broader implications.

@DecadentIpsum @dqve @ignaciodiazb @NotTimTam can one of you please share a minimal repo that reproduces this issue? I'm not familiar with Next.js and don't have much time to figure out by myself.

DecadentIpsum commented 1 year ago

@simonbrunel thanks a lot for your interest in resolving this issue 🙂

Here is a minimal repo with the reproduction of the issue https://codesandbox.io/s/elated-haze-d3fj4w?file=/pages/index.js

Fish1 commented 1 year ago

Same issue here. I am using sveltekit version 1.0 and Vite 4.0

The big change with Vite4 was the switch to Rollup3.

That's interesting because the dev server built into vite uses ESBuild. The dev server using ESBuild runs the project just fine.

I only run into issues when I try to use Rollup3 to build the project.

stockiNail commented 1 year ago

hanks @stockiNail for the info. While you are probably right, I don't want to blindly push these changes but first would like to experiment with the reported cases. Also, we need to be sure that it doesn't break existing integrations since changing type: "module" may have broader implications.

@simonbrunel Maybe it can help: https://github.com/chartjs/Chart.js/pull/10914#issuecomment-1326685660 CommonJS is not supported anymore from CHART.JS 4.

simonbrunel commented 1 year ago

Thanks @stockiNail! I'm very surprised about such decision. I'm also wondering if it's actually the root cause of plugins breaking in NextJS or if it's unrelated.

stockiNail commented 1 year ago

Thanks @stockiNail! I'm very surprised about such decision. I'm also wondering if it's actually the root cause of plugins breaking in NextJS or if it's unrelated.

It shouldn't be related (but my knowledge is so low about JS packaging, therefore don't trust my answer!).

epleaner commented 1 year ago

Also getting this with "next": "13.0.3", "chart.js": "4.0.1", and "chartjs-plugin-datalabels": "2.2.0".

Hopefully a fix is coming in soon.

dahsser commented 1 year ago

Same here, having problems with chart.js v4 and the latest version of "chartjs-plugin-datalabels"

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './helpers' is not defined by...

Hoping for a soon fix, thanks.

Fish1 commented 1 year ago

Noticed that chartjs 4.1.1 was released yesterday.

Bumped up the version to 4.1.1 in the previously shared codesandbox, and all appears to be working!

https://codesandbox.io/s/objective-panka-ewx6tu

DecadentIpsum commented 1 year ago

I can confirm that ChartJS 4.1.1 seems to clear the error!

simonbrunel commented 1 year ago

That's a good news! Thanks @Fish1 and @DecadentIpsum for checking and keep us updated.

@dqve @ignaciodiazb @NotTimTam @epleaner @dahsser can you guys also confirm that Chart 4.1.1 fixes your issue?

ignaciodiazb commented 1 year ago

Yes. chart.js 4.1.1 solves the problem

anthgrim commented 1 year ago

I had the same problem using nextJs. Chart.js 4.1.1 and chartjs-plugin-datalabels 2.2.0 worked perfectly

imronpuji commented 1 year ago

the problem with your chart.js version just upgrade chart.js version to 4.2.1, this is work

Screen Shot 2023-04-06 at 12 24 59 Screen Shot 2023-04-06 at 12 25 37