socket.io
socket.io copied to clipboard
Module not found: Error: Can't resolve 'fs' in './node_modules/socket.io/dist'
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
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/
Closed due to inactivity, please reopen if needed.