-
Notifications
You must be signed in to change notification settings - Fork 7
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
Working with Sveltekit #90
Comments
Thank you for reporting this issue. If we dont add this plugin, we get an error when using
So if you would clone our code and remove |
I feel like I'm still missing a few things. When does rollup run in this context? before the code is distributed or on the consumers end? Also, if this is the only occurrence of that code, is it that imortant to pull the name out of the |
There are two ways we could solve this. Either we provide a workaround for svelte kit or we could also change Vega-Lite to compile js files that have the version already in them. To try the latter, you could use one of our compiled bundles instead of the js source files we directly generate from the ts sources. |
Hi Sam thanks for bringing this up! Roping in @domoritz for this. As far as I can tell, the core vega package imports some JSON files directly, so it requires rollup to have a JSON loader. I think the best solution would be to update Vega itself, but it might require a hefty change. |
So I want to clarify I few things.
|
Relevant issue: mhkeller/layercake#41 I created a blank sveltekit project w/ svelte-vega and get the same fast-deep-equal error. |
Maybe also related: d3/d3#3469 |
I'm pretty sure the issue is not JSON but |
Still learning my way around these things, but I don't think I'm using rollup because sveltekit. |
Yup you're right it uses Vite it looks like. This is the file it fails for, seems to be some weird common.js issue I'm guessing, I don't know enough to debug it well: https://github.com/epoberezkin/fast-json-stable-stringify/blob/master/index.js Honestly likely a svelte-kit issue, they should be able to handle common.js type imports? |
I'm not totally convinced because as a workaround I can use |
AH yes okay then it's probably how we are building the widget. I'll try to check tomorrow, though it looks like we are exporting as esm. |
fwiw I just tried d3 7.0 which is all esm and it gives the same vite ssr error. |
Just d3 by itself? Very interesting, might be worth posting an issue there, they might have more expertise/ideas about the problem? |
Note that D3 v7 came out this week. |
Curious if anyone has gotten this working in svelte-kit yet? AFAICT, the problem is that svelte-vega works as an ES6 module but some of the imports aren't pure ES and svelte-kit breaks down the chain. With the D3 v7 problem mentioned above, my workaround has been to use compiled
[edit: redefining 'equal' in this code from using 'fast-deep-equal' to {JSON.stringify(a) === JSON.stringify(b)} does allow things to build in svelte-kit, although then there are more problems down the line.] |
fast-deep-equal adds support for es modules in epoberezkin/fast-deep-equal#105. However, I think sveltekit would need to support commons since it's unrealistic to expect everyone to only use esmodules at this point. |
I think it's probably how we export our module, I can try to look at it today. |
Maybe it's reasonable to expect svelte users to be using ES import syntax in their code? Also, don't rush this on my account ahead of svelte-kit stability--I think sticking with vega-embed will fit my use case better anyway, because I need to add event listeners on the rendered chart. |
Alright I tried reimplementing the package using the sveltekit packaging option (https://kit.svelte.dev/docs#packaging) and it still fails to import. It looks like a lot of Svelte imports for sveltekit are either experimental or very broken with vite (vitejs/vite#4231). Hopefully it stabilizes a bit and we can make it work :/ |
Thank you for looking into this @cabreraalex. Do we support adding event listeners? |
Oh yeah on that note, we do! Maybe we can document it better, looks something like this, same as vega-embed: |
Does any one has any progress with SvelteKit? |
Uninteresting update, I tried this again and it still fails with SSR/Vite issues, specifically on trying to import |
Hi, I encountered the same issue while using plain vite-svelte and after looking at vite's docs I figured out how to get svelte-vega to work with vite. The problem is related to vite's dependencies pre-building. As mentioned in vite's docs this behavior can be customized. Adding the following lines in vite's config file solves the problem: optimizeDeps: {
include: ["fast-deep-equal"],
} After testing I got more errors with other packages, so I included all I found in the console error message. The whole svelkit config: const config = {
kit: {
// hydrate the <div id="svelte"> element in src/app.html
target: "#svelte",
vite: {
optimizeDeps: {
include: [
"fast-deep-equal",
"semver",
"json-stringify-pretty-compact",
"clone",
"fast-json-stable-stringify",
],
},
},
},
}; With that, I was able to use svelte-vega with sveltkit and plain vite-svelte. |
Thanks for sharing. Is that something we can do automatically from our side? If not, could you send a pull request to upstate the readme with a note? |
At the moment it's something specific to Vite's way of handling dependencies in development, so a description in the readme will do. I've sent a pull request as suggested #208 |
I have version working with SvelteKit we'll try to merge soon at the sveltekit branch |
🎉 This issue has been resolved in version 1.1.1 🎉 The release is available on: Your semantic-release bot 📦🚀 |
I'm trying to set up a project to use vega within sveltekit for a blog. I'm getting errors of
module is not defined
when I try to import fromsvelte-vega
; I'm fairly confident this has something to do with the rollup JSON plugin, since I can't install that in the context of sveltekit. However, I am able to import json files as modules without a problem in my own code, so I'm a little surprised that's an issue.Why is that rollup plugin necessary? I'd like to help contribute here if I can, getting more involved with vega is something I've been excited about for a while, but I'm not sure I have all the context necessary to jump in.
The text was updated successfully, but these errors were encountered: