Closed maemigh closed 3 months ago
The error is self explanatory. In the browser you have to use the WebSocket client that ships with the browser, not ws
.
This code does not run in the browser. The error occurs when using ws inside a +server.ts route.I think it is probably because the adapter-cloudflare is built with
const result = await esbuild.build({
platform: 'browser',
conditions: ['worker', 'browser'],
sourcemap: 'linked',
target: 'es2022',
entryPoints: [`${tmp}/_worker.js`],
outfile: `${dest}/_worker.js`,
allowOverwrite: true,
format: 'esm',
bundle: true,
loader: {
'.wasm': 'copy'
},
external,
alias: Object.fromEntries(compatible_node_modules.map((id) => [id, `node:${id}`])),
logLevel: 'silent'
});
where platform is browser. Guess I'll open an issue there.
Yes, I guess the issue arises from that platform: 'browser'
option.
I'm closing this as answered.
Is there an existing issue for this?
Description
When using adapter-cloudflare with sveltekit, this error comes up:
Error: ws does not work in the browser. Browser clients must use the native WebSocket object
It works fine with the same project when running with Vite.
ws version
8.16.0
Node.js Version
v21.5.0
System
System: OS: macOS 14.3.1 CPU: (8) arm64 Apple M1 Memory: 75.34 MB / 16.00 GB Shell: 5.9 - /bin/zsh
Expected result
import to load
Actual result
No response
Attachments
No response