Skip to content

Isomorphic build support #9436

Description

@benmccann

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions