-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing helpers
and auto
need to be added too. And the type
should not be changed, at least not before v4.
@@ -4,6 +4,11 @@ | |||
"description": "Simple HTML5 charts using the canvas element.", | |||
"version": "3.5.1", | |||
"license": "MIT", | |||
"type": "module", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you have to add "type": "module"
? I expect it might be a breaking change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)