socket.io icon indicating copy to clipboard operation
socket.io copied to clipboard

Module not found: Error: Can't resolve 'fs' in './node_modules/socket.io/dist'

Open vivasvan1 opened this issue 3 years ago • 1 comments

Describe the bug In line new socketio.Server()

Module not found: Error: Can't resolve 'fs' in './node_modules/socket.io/dist'
 @ ./node_modules/socket.io/dist/index.js 27:13-26
 @ ./src/ts/server/UltimateSocket.ts
 @ ./src/ts/world/World.ts
 @ ./src/ts/sketchbook.ts

To Reproduce

git clone https://github.com/swift502/Sketchbook.git npm install socket.io add few lines in src/ts/world/World.ts in the constructor

import * as socketio from 'socket.io';
new socketio.Server(port, {
            cors: {
                origin: "http://localhost:8080",
                methods: ["GET", "POST"],
            },
        });

Please fill the following code example:

Socket.IO server version: 4.5.0

Server

this.io = new socketio.Server(port, {
            cors: {
                origin: "http://localhost:8080",
                methods: ["GET", "POST"],
            },
        });

Socket.IO client version: x.y.z

Client

not needed.

Expected behavior Not throw Module not found: Error: Can't resolve 'fs' in 'socket.io/dist'.

Platform:

  • Device: Acer Nitro 5
  • OS: Ubuntu 20.05

vivasvan1 avatar May 04 '22 05:05 vivasvan1

It seems the project https://github.com/swift502/Sketchbook is a front-end project, isn't it? In that case, you should rather use the socket.io-client package.

Reference: https://socket.io/docs/v4/client-initialization/

darrachequesne avatar May 04 '22 20:05 darrachequesne

Closed due to inactivity, please reopen if needed.

darrachequesne avatar Oct 14 '22 08:10 darrachequesne