Phoenix Channels "no connection to the server" in CI
The Phoenix JS client refuses to join a channel while its underlying Socket is not connected, reporting "unable to join, no connection to the server". The Socket transport never opened, so no join can be sent.
What this error means
A browser or JS test logs "unable to join, no connection to the server" when calling channel.join(), because socket.connect() did not establish the WebSocket first.
unable to join, no connection to the server
at Channel.join (phoenix.js:...)Common causes
join() called before the socket connected
The test joined a channel immediately after constructing the Socket, before the WebSocket transport had opened.
The endpoint or WebSocket route is unreachable
A wrong socket URL, a server not yet listening, or a blocked /socket/websocket route means the transport never opens.
How to fix it
Connect the socket and wait for open
- Call
socket.connect()and wait for theonOpencallback before joining. - Confirm the socket URL matches the server endpoint route.
- Ensure the Phoenix server is listening before the test runs.
const socket = new Socket('/socket');
socket.onOpen(() => channel.join());
socket.connect();Verify the socket endpoint
The URL must resolve to the server's socket route; a mismatch prevents the transport from opening.
const socket = new Socket('ws://localhost:4000/socket');How to prevent it
- Wait for socket onOpen before joining any channel.
- Keep the client socket URL aligned with the endpoint route.
- Ensure the Phoenix server is listening before browser tests run.