Closed benmccann closed 2 years ago
Thanks for working on this Ben! I'm still seeing problems during Vite SSR phase here, where it tries to load node.js
which uses require
.
More details below, but I've also created a minimal reproduction here: https://github.com/dimfeld/sveltekit-with-svelte-query. This repo is set up with pnpm and so you can override the version of broadcast-channel
used in the pnpm.overrides
section of package.json. Hope it helps!
So first I see this error:
ReferenceError: require is not defined
at /node_modules/.pnpm/broadcast-channel@4.0.0/node_modules/broadcast-channel/src/methods/node.js:6:14
at instantiateModule (/home/dimfeld/projects/vite/packages/vite/dist/node/chunks/dep-ea6d097e.js:73433:166)
Notably, this is the version in the src
directory. I see a comment in the source that it's faster to run the non-transpiled version here, but it does seem to cause issues. If I change the import to the transpiled version (./methods/node.js
) then it gets past that, but actually runs into issues with in babel runtime's async transformation code.
ReferenceError: module is not defined
at /node_modules/.pnpm/@babel+runtime@7.14.8/node_modules/@babel/runtime/helpers/asyncToGenerator.js?v=710ddb8b:35:1
at instantiateModule (/home/dimfeld/projects/vite/packages/vite/dist/node/chunks/dep-ea6d097e.js:73433:166)
Thanks for the reproduction. That does help. I'll close this for now
I've never used svelte-query
@benmccann why? Can I ask you what are you using right now? Will you ever use it in the future?
It's nothing against svelte-query. There's just more libraries out there than I've had a chance to use :smile: I may use it in the future
Yes, that's what I meant. I just don't know them. Can you tell me what they are?
Fixes https://github.com/SvelteStack/svelte-query/issues/45. I hope. Note that I've never used
svelte-query
and haven't tested this. That being said, I got some changes intobroadcast-channel
that I believe should make it compatible with SvelteKit. You might have to defineprocess.browser
if Vite doesn't, but besides that I hope it should just work