Skip to content
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

ReferenceError: WebSocket is not defined #648

Open
somiryu opened this issue May 29, 2022 · 3 comments
Open

ReferenceError: WebSocket is not defined #648

somiryu opened this issue May 29, 2022 · 3 comments

Comments

@somiryu
Copy link

somiryu commented May 29, 2022

file:///{{url}}/node_modules/svelte-websocket-store/src/index.mjs:54
socket = new WebSocket(url, socketOptions);
^

ReferenceError: WebSocket is not defined
at open (file:///{{url}}/node_modules/svelte-websocket-store/src/index.mjs:54:5)
at Object.subscribe (file:///{{url}}/node_modules/svelte-websocket-store/src/index.mjs:84:7)
at Proxy.subscribe (/{{url}}/node_modules/svelte/internal/index.js:59:25)
at eval (/src/routes/dashboard.svelte:36:48)
at Object.$$render (/{{url}}/node_modules/svelte/internal/index.js:1758:22)
at Object.default (/.svelte-kit/generated/root.svelte:58:129)
at eval (/src/routes/__layout.svelte:85:75)
at Object.$$render (/{{url}}/node_modules/svelte/internal/index.js:1758:22)
at eval (/.svelte-kit/generated/root.svelte:50:126)
at $$render (/{{url}}/node_modules/svelte/internal/index.js:1758:22)

Node.js v18.2.0

@somiryu
Copy link
Author

somiryu commented May 29, 2022

Using Svelte-kit

@manuganji
Copy link

I don't see any lines in the source that make it work for the node js environment. The index.mjs directly refers to WebSocket which would only work if you're inside the browser. So this doesn't work for Svelte Kit (at least as of today).

@JDR42
Copy link

JDR42 commented Aug 12, 2022

FYI, to use with SvelteKit you can employ conditionals with browser from $app/env to ensure this library is only attempted to run on the client-side.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants