socketio / socket.io

Realtime application framework (Node.JS server)
https://socket.io
MIT License
61.26k stars 10.12k forks source link

Error [RollupError]: "default" is not exported by "node_modules/ws/lib/websocket.js", imported by "node_modules/ws/wrapper.mjs". #5193

Open prljav opened 2 months ago

prljav commented 2 months ago

Describe the bug A clear and concise description of what the bug is. Cannot import io from socket.io-client To Reproduce Use @kellnerd/userscript-bundler to try to bundle import { io } from "socket.io-client" Please fill the following code example:

Socket.IO server version: x.y.z none

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: x.y.z

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 have the IO object

Platform:

Additional context Add any other context about the problem here. no

prljav commented 2 months ago

NOTE: could be issue with the bundler, if it is someone please help :P

darrachequesne commented 1 month ago

Hi! rollup must be configured to use the browser-specific version of the package:


export default {
  // ...
  plugins: [
    resolve({
      browser: true,
    }),
  ],
};

Is that your case?

Reference: https://socket.io/docs/v4/client-with-bundlers/#rollupjs