chartjs/chartjs-plugin-datalabels

Error running the latest chartjs-plugin-datalabels with NextJS

DecadentIpsum opened this issue ยท 21 comments

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

Same issues here.

@simonbrunel any ideas? :)

This package uses chart.js 3.0

@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.

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

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

Same here, no other plugins. Just the latest version of both packages.
Screenshot 2022-12-12 at 1 13 41 PM

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.

@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

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.

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: chartjs/Chart.js#10914 (comment)
CommonJS is not supported anymore from CHART.JS 4.

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.

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!).

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.

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

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

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

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?

Yes. chart.js 4.1.1 solves the problem

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

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