Fix package.json entry points#9405
Conversation
3077853 to
2ab2632
Compare
2ab2632 to
5006340
Compare
|
After these changes, A simple, non-module package, requiring chart.js would fail:
While without these changes both non-module and module packages load chart.js just fine in node. |
|
It actually looks like current Node.js is unable to work with Dual CommonJS/ES module packages without using the I'm still unsure what the actual issue is with SvelteKit and commonjs modules. |
f41f3e9 to
e75c4be
Compare
|
Duh. I should have caught that. Thanks for reviewing. I've updated it to work with both Node and Vite now. Vite has no issue with CJS modules. If it did then you couldn't run anything with it 😄 It's only server-side UMD that it has an issue with |
So it use the esm for client side and the same code is used server side, but it loads the cjs (because of no type="module" or .mjs extension) and thus has different exports and that fails? |
|
Also, do we really need to have a cjs build, is it just about loading the different package server vs client? I'd assume the UMD package works the same as before (and would not be used in this vite case anymore). Could also be a bit less breaking to rename the esm build to |
e75c4be to
3764369
Compare
3764369 to
a9c7160
Compare
I believe Vite will prefer
Yes, for Vite we would because it needs either CJS or ESM on the server and I believe the only way it will use the ESM is if we tell it
Good thought, but I just tested and Vite isn't accepting it if I put
I removed |
|
This would be a breaking change, because the format of the |
|
The proposed changes do not work for the vite bug. Its hard to test, because vite considers linked modules source and just linking chart.js without changes makes it work. So you'll need to edit it directly in node_modules to see if changes work. I found a three ways to make things work:
const config = {
kit: {
// hydrate the <div id="svelte"> element in src/app.html
target: '#svelte',
vite: {
ssr: {
noExternal: ['chart.js']
}
},
},
};The vite SSR is experimental. I don't think we should "fix" chart.js for something experimental. |
|
Thanks a lot @kurkle for figuring out impacts of this PR but also looking for solutions for Vite/Svelte. I would expect these frameworks to pick the I'm also concerned about the suggested changes because Chart.js is integrated in so many different ways that we can't assume how the UMD build provided as If we change |
|
I am definitely wary of changing package.json as I think it could easily have unintended effects. Maybe we can add this into the documentation. We already have the "integrations" page, but that is already getting too long. Perhaps it's better to make a section in the left menu for "Advanced Integrations" and add a page for each system that needs custom documentation |
Oh wow. That's evil. I'm not sure how you figured that out, but am happy to know that. It does explain some things I was confused by Thanks @kurkle for the investigation! I'll go ahead and close this and file an issue to revisit for 4.0 |
Closes #9404