Skip to content
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

Does not work with Vite.js and vue 3. #1492

Closed
Taykavol opened this issue Sep 3, 2021 · 6 comments
Closed

Does not work with Vite.js and vue 3. #1492

Taykavol opened this issue Sep 3, 2021 · 6 comments
Labels
bug Something isn't working
Milestone

Comments

@Taykavol
Copy link

Taykavol commented Sep 3, 2021

Describe the bug
The same code with webpack works. But Vite.js + Vue 3 is not. There is even no requests. Probably it's not problem of socket.io-client package but something wrong with socket.io-client.

To Reproduce

Socket.IO server version: 4.2.0

Server

import { Server } from "socket.io";

const io = new Server(3000, {});

io.on("connection", (socket) => {
  console.log(`connect ${socket.id}`);

  socket.on("disconnect", () => {
    console.log(`disconnect ${socket.id}`);
  });
});

Socket.IO client version: 4.2.0

Client

import { io } from "socket.io-client";

const socket = io("ws://localhost:3000/", {});

socket.on("connect", () => {
  console.log(`connect ${socket.id}`);
});

socket.on("disconnect", () => {
  console.log("disconnect");
});

Expected behavior
Expected to see console.log messages on server and client. But it's not working at all.

Platform:

  • OS: [e.g. Windows 10]
@Taykavol Taykavol added the bug Something isn't working label Sep 3, 2021
@darrachequesne
Copy link
Member

Could you please provide a complete example reproducing the issue? Thanks!

@Taykavol
Copy link
Author

Taykavol commented Sep 3, 2021

Could you please provide a complete example reproducing the issue? Thanks!

I am sorry, not expert in programming explaining. So the problem is the simplest code above works with webpack(vue-cli) but not work with vite.js +vue.

I created full repo example, https://github.com/Taykavol/socket.io-vite-and-vue-cli-example

Client
`import {io} from 'socket.io-client'
// io is works with webpack but not working with vite

const socket = io("ws://localhost:4000/", {});

socket.on("connect", () => {
// Works great! with webpack
alert(connect ${socket.id})
});

socket.on("disconnect", () => {
console.log("disconnect");
});

@Taykavol
Copy link
Author

Taykavol commented Sep 3, 2021

Also, now I checked that the versons(client) 4.1.x works great (event with socket.io server 4.2.0) but something wrong with 4.2.0 client.

@philippdormann
Copy link

can confirm.
v4.1.3 works fine
v4.2.0 breaks.

not sure how to debug this

also see vitejs/vite#4798

@darrachequesne
Copy link
Member

Please see my answer here: vitejs/vite#4798 (comment)

@darrachequesne
Copy link
Member

It should be fixed now:

Please reopen if needed.

@darrachequesne darrachequesne added this to the 4.3.0 milestone Apr 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants