Add package.json exports property#9597
Conversation
|
@benmccann does this resolve #9436 ? |
| "type": "module", | ||
| "exports": { | ||
| "import": "./dist/chart.esm.js", | ||
| "require": "./dist/chart.js" |
There was a problem hiding this comment.
You'd also have to export package.json. Some build tools such as rollup-plugin-svelte will try to consume it. I'm not sure if this is exactly the right syntax, but I think you could do it with:
".": {
"import": "./dist/chart.esm.js",
"require": "./dist/chart.js",
}
"./package.json": "./package.json"
There was a problem hiding this comment.
I'm guessing helpers and auto need to be added too. And the type should not be changed, at least not before v4.
| "description": "Simple HTML5 charts using the canvas element.", | ||
| "version": "3.5.1", | ||
| "license": "MIT", | ||
| "type": "module", |
There was a problem hiding this comment.
do you have to add "type": "module"? I expect it might be a breaking change
There was a problem hiding this comment.
the tests are failing and I expect this line is why
|
I haven't tested, but yes, I imagine it would fix that issue |
|
Discussion in #9405 is related (also has a workaround for vite). |
|
I worked around this issue by moving my I'll close this PR for now since I don't have enough chartjs knowledge to push it forward, but I hope it can serve as inspiration for a future PR. Thanks! |
This allows modern build systems (vite) to properly use the correct module type (ESM).
When this is not present, when using Chart.js in Sveltekit, when running a build it will give an error
Named export 'Chart' not found. The requested module 'chart.js' is a CommonJS module, which may not support all module.exports as named exports.More info: https://medium.com/swlh/npm-new-package-json-exports-field-1a7d1f489ccf
Also, for background: sveltejs/kit#1498 (comment) and sveltejs/kit#928 (comment)