-
-
Notifications
You must be signed in to change notification settings - Fork 33
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
WebSocket / WebSocketPair not available #154
Comments
Thanks for the issue. This is similar to https://discord.com/channels/830184174198718474/1168702512782659664 |
Thanks! Would it be possible to import https://www.npmjs.com/package/@miniflare/web-sockets and provide it as a global via vite config in the adapter? Probably not that straightforward 😅 |
I need to validate this actually works, but something like this might be the best workaround for now: let WebSocketImpl: typeof WebSocket;
if (import.meta.env.DEV) {
const wsModule = await import("ws");
WebSocketImpl = wsModule.default as unknown as typeof WebSocket;
} else {
// Fallback to the global `WebSocket` in production
WebSocketImpl = WebSocket;
}
let WebSocketPairImpl: typeof WebSocketPair;
if (import.meta.env.DEV) {
// Use @miniflare/web-sockets in development
const { WebSocketPair: MFWebSocketPair } = await import(
"@miniflare/web-sockets"
);
WebSocketPairImpl = MFWebSocketPair as unknown as typeof WebSocketPair;
} else {
// Assume WebSocketPair is globally available in production (Cloudflare Workers)
WebSocketPairImpl = WebSocketPair;
}
export { WebSocketImpl as WebSocket, WebSocketPairImpl as WebSocketPair }; |
@alexanderniebuhr ive just seen https://vitejs.dev/blog/announcing-vite5-1.html Would this new api allow us to hook directly into workerd? Found via https://twitter.com/pcattori/status/1755632675103080521?t=C0blapvcX2HNq-zTgw3vpw&s=19 |
We are looking into this internally already, but that's still experimental. |
I think this might be moot anyway based on withastro/astro#10057 (comment) :( |
Astro Info
Describe the Bug
I'm running astro with the Cloudflare adapter, and everything is working great apart from the
WebSocket
andWebSocketPair
classes not being available in the server runtime.Local mode says:
uses a local runtime powered by miniflare and workerd, which supports Cloudflare’s Bindings.
. I might have missed the point here, but I was hoping that those classes would be available since they are on miniflare / workderd?What's the expected result?
Works just like Cloudflare (as the declarations are available via:
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-8ghpcm?file=src%2Fpages%2Findex.ts
Participation
The text was updated successfully, but these errors were encountered: