Running @tomic/lib in Node (non-browser) context
joepio opened this issue · 0 comments
joepio commented
When running @tomic/lib on SvelteKit's server side functions, @Polleps just got some errors:
ReferenceError: WebSocket is not defined
at startWebsocket (file:///Users/polleps/Documents/Argu/wonenatthepark/node_modules/@tomic/lib/dist/src/websockets.js:61:18)
at Store.getWebSocketForSubject (file:///Users/polleps/Documents/Argu/wonenatthepark/node_modules/@tomic/lib/dist/src/store.js:173:45)
at Store.fetchResource (file:///Users/polleps/Documents/Argu/wonenatthepark/node_modules/@tomic/lib/dist/src/store.js:150:23)
at Store.getResourceLoading (file:///Users/polleps/Documents/Argu/wonenatthepark/node_modules/@tomic/lib/dist/src/store.js:209:22)
at /node_modules/@tomic/svelte/dist/index.js:56:9
at Object.b [as subscribe] (/node_modules/@tomic/svelte/dist/index.js:43:43)
at v (/node_modules/@tomic/svelte/dist/index.js:9:15)
at d (/node_modules/@tomic/svelte/dist/index.js:14:10)
at Module.V (/node_modules/@tomic/svelte/dist/index.js:64:11)
at +page.svelte:12:14
This is because the WebSocket class does not exist server side. The problem occurs in getWebSocketForSubject
, in which I don't have window
check.
I should test for these types of issues. Not sure how.