Can I use websockets with nextjs
Unanswered
Red ant posted this in #help-forum
Red antOP
Websockts need a server. Next seems to be serverless. So websockets doesnt work with nextjs?
16 Replies
you need an external service to have websockects with nextjs as you correctly guessed
Red antOP
Edge runtime mention websockets
i haven't tried it myself, so going off other posts
but maybe edge runtime is diferent... idk
i just have heard it doesn't work (well maybe)
Red antOP
Is edge and servless same thing?
kinda and kinda not
edge is very instant and small code vs serverless is more of an actual server with cold boot time but more resources
also edge is close to user whereas serverless is one place
Red antOP
Oh ok
also:
"[Websocket? Unfortunately, Next.js is built for serverless, which means you can’t run a websocket server without using a custom node.js server. Custom server isn’t allowed by platforms like Vercel, also not a recommended way.
Generally, we will use 3rd party services, such as Ably Realtime. They work great for serverless environments. Websocket needs an actual persistent server, and Next.js doesn’t come with that by default. ](https://nextjs-forum.com/post/1140603766396158032#message-1140605090621837472)"
@Red ant Oh ok
yeah, they are in theory but in vercel context there are some diferences
@riský but maybe edge runtime is diferent... idk
Red antOP
I enabled edge runtime
Got
Got
Module not found: Can't resolve 'crypto'yeah edge server doesn't support node specifc things and only normal browser JS
Red antOP
Also prob cuz im using socket.io
Nvm get the same error without using socket.io