close
The Wayback Machine - https://web.archive.org/web/20230108151105/https://github.com/chartjs/Chart.js/issues/9436
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

Isomorphic build support #9436

Closed
benmccann opened this issue Jul 18, 2021 · 6 comments
Closed

Isomorphic build support #9436

benmccann opened this issue Jul 18, 2021 · 6 comments

Comments

@benmccann
Copy link
Contributor

benmccann commented Jul 18, 2021

Chart.js does not work with Vite / SvelteKit out of the box. This is because Chart.js provides a build via the main field in package.json which provides just a default export. Meanwhile it provides a build in module which provides named exports. Vite tries to use the module build on the client and the main build on the server which causes the build to fail because you can't write code that is compatible with both these packages. To work around this, you can specify the option vite.ssr.noExternal: ['chart.js'], but this is hard for users to figure out and it'd be much nicer to provide builds that are the same shapte

There are a couple things we could do:

  • We should put a build in main that uses the same entry file as our ESM build and add "type": "module" to package.json. This is probably the best option
  • We could remove main. Chart.js isn't really that useful on the server-side, so we could just stop telling Vite that we have a server-side build. It would still try to build it on the server, but would fallback to the ESM implementation
@simonbrunel
Copy link
Member

simonbrunel commented Jul 19, 2021

An interesting thread about moving to pure ESM package.

Chart.js isn't really that useful on the server-side...

I don't fully agree, even if it's clearly not the main usage, Chart.js is used server side (though I don't know how it's imported). So whatever solution is adopted, we should make sure to still support server-side use cases in pure node environment.

@etimberg
Copy link
Member

etimberg commented Jul 19, 2021

I recall a few threads of folks doing server side rendering using node-canvas to generate images for reports

@dangreen
Copy link
Collaborator

dangreen commented Aug 7, 2022

@benmccann Does #10525 solve this issue?

@benmccann
Copy link
Contributor Author

benmccann commented Aug 7, 2022

Yes! Thanks

@rpf3
Copy link

rpf3 commented Aug 8, 2022

@dangreen any idea when it will be released?

@dangreen
Copy link
Collaborator

dangreen commented Aug 8, 2022

@rpf3 it will be released in v4. You can follow the progress here

https://github.com/chartjs/Chart.js/milestone/23

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants