-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
adapter-cloudflare doesn't work with ws #12007
Comments
I think you have to use the workers WebSocket API instead of the node.js Unless you specifically need it maybe it can be pollyfilled or enabled through node compat options? |
I have enabled the node compat options, but this is specifically failing (on the +server.ts endpoint) because the
and the adapter is being built with The changelog indicates that adapter-cloudflare was once There are more details here: #8122 Also, I believe |
Can you provide a minimal reproduction in the form of a downloadable / online repository? That would be a great help. |
Sure. Install wranger, run with Then browse to |
The repository you've linked only has a README.md |
sorry, cant believe i did that. just synced it. |
After patching the adapter with the build options from this PR https://github.com/sveltejs/kit/pull/8122/files it does give a better error message. But I don't think it works with Cloudflare Workers. > Using @sveltejs/adapter-cloudflare
✘ [ERROR] Could not resolve "zlib"
node_modules/ws/lib/permessage-deflate.js:3:21:
3 │ const zlib = require('zlib');
╵ ~~~~~~
Cannot use "zlib" when deploying to Cloudflare.
✘ [ERROR] Could not resolve "http"
node_modules/ws/lib/websocket-server.js:6:21:
6 │ const http = require('http');
╵ ~~~~~~
Cannot use "http" when deploying to Cloudflare.
✘ [ERROR] Could not resolve "https"
node_modules/ws/lib/websocket.js:6:22:
6 │ const https = require('https');
╵ ~~~~~~~
Cannot use "https" when deploying to Cloudflare.
✘ [ERROR] Could not resolve "http"
node_modules/ws/lib/websocket.js:7:21:
7 │ const http = require('http');
╵ ~~~~~~
Cannot use "http" when deploying to Cloudflare.
✘ [ERROR] Could not resolve "net"
node_modules/ws/lib/websocket.js:8:20:
8 │ const net = require('net');
╵ ~~~~~
Cannot use "net" when deploying to Cloudflare.
✘ [ERROR] Could not resolve "tls"
node_modules/ws/lib/websocket.js:9:20:
9 │ const tls = require('tls');
╵ ~~~~~
Cannot use "tls" when deploying to Cloudflare.
✘ [ERROR] Could not resolve "url"
node_modules/ws/lib/websocket.js:12:24:
12 │ const { URL } = require('url');
╵ ~~~~~
Cannot use "url" when deploying to Cloudflare. The neon docs states you only need // don't do this if you have access to the WebSocket API
import ws from 'ws';
neonConfig.webSocketConstructor = ws; |
In fact you don't need to use any additional third-party websockets. For convenience, I wrote a vite plug-in to integrate websocket. |
I am also experiencing this issue and would love for Workers to add support for more NPM libraries @craigsdennis can you chime in here with ideas? |
Describe the bug
ws (https://github.com/websockets/ws/) doesn't work when using adapter-cloudflare. ws fails to run because it thinks it's running in the browser. I think this is because adapter-cloudflare is built with
platform: browser
and the import ends up calling itsbrowser.js
containingReproduction
When used inside +server.ts
results in the error
Logs
No response
System Info
Severity
annoyance
Additional Information
The text was updated successfully, but these errors were encountered: