-
Notifications
You must be signed in to change notification settings - Fork 10.1k
Does not work with Nuxt 3 in prod with latest packages #5208
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
Comments
Seems like i've spent too much time trying to figure out reason why it suddenly stopped working. Solution for 0.3.x crossws versions: nitroApp.router.use(
'/socket.io/',
defineEventHandler({
handler(event) {
// @ts-expect-error private method
engine.handleRequest(event.node.req, event.node.res)
event._handled = true
},
websocket: {
open(peer) {
// @ts-expect-error private method
const internal = peer._internal
const req = internal.request
// @ts-expect-error private method
engine.prepare(req)
// @ts-expect-error
const rawSocket = internal.request._req.socket
const websocket = internal.ws
// @ts-expect-error private method
engine.onWebSocket(req, rawSocket, websocket)
}
}
})
) |
It doesn't work for me with https :
It works : nitroApp.router.use(
"/socket.io/",
defineEventHandler({
handler(event) {
// @ts-expect-error private method
engine.handleRequest(event.node.req, event.node.res);
event._handled = true;
},
websocket: {
open(peer) {
// @ts-expect-error private method and property
engine.prepare(peer._internal.nodeReq);
// @ts-expect-error private method and property
engine.onWebSocket(peer._internal.nodeReq, peer._internal.nodeReq.socket, peer.websocket);
}
}
})); |
This sound to me like an issue with either Nitro or unjs/crossws but not Nuxt and not Socket.io ? |
The guide has been updated to work with The example too: https://github.com/socketio/socket.io/tree/main/examples/nuxt-example Thanks for the heads-up! |
This issue seems to not be fixed, and the minimal example does not work because of the issue outlined above. It does work fine in dev but does not for production. I can observe the same behavior in my application after updating. Accessing
|
The issue was resolved by the latest (3.14) nuxt release, which upgraded nitropack to the 2.10 version which also uses crossws >=0.3 🥳 I speculate that the issue stemmed from socket.io and nitropack (nuxt server layer) using different crossws version, leading to incompatibilities. To resolve the issue, upgrade to the latest nuxt version (3.14). If this is for any reason not possible for you, you could try to just try to update the nitropack dependency to >=2.10 (I have not tested this). |
Method from guide worked fine until nuxt/nitro updated
crossws
version to 0.3.0, wherepeer.ctx
is moved topeer._internal
. Simple change fromctx
to_internal
will work only in dev mode, but_iternal
areundefined
in production mode.Possible temp solution
Downgrade
crossws
version from0.3.x
to0.2.4
- seems like it was last version that worksNot really socket.io bug, but probably you'll want to update guide
The text was updated successfully, but these errors were encountered: