I'm having quite a frustrating issue with something that seems trivial.
I'm running an express application on a node.js server, written in ES6 and compiled using webpack. It compiles without any errors except from the following warning:
../node_modules/socket.io/lib/index.js 113:11-32
0:0 warning Critical dependency: the request of a dependency is an expression
(although I'm not sure whether this is linked to my current problem)
However, when I start the server I get the following error:
Error: Cannot find module 'socket.io-client/dist/socket.io.js'
at Function.webpackEmptyContext [as resolve] (webpack:///../node_modules/socket.io/lib_sync?:2:10)
at resolvePath (webpack:///../node_modules/socket.io/lib/index.js?:113:100)
at Server.serveClient (webpack:///../node_modules/socket.io/lib/index.js?:116:25)
at new Server (webpack:///../node_modules/socket.io/lib/index.js?:53:8)
at Function.Server [as listen] (webpack:///../node_modules/socket.io/lib/index.js?:44:41)
at new Socket (webpack:///./server/socket.js?:10:98)
Socket class:
import io from 'socket.io';
export default class Socket {
constructor(server) {
this.io = io.listen(server);
this.io.on('connection', (socket) => {
// Handle connection
});
}
}
The server parameter is the object returned from the express.listen()
function.
I installed socket.io using the command npm install socket.io --save
, subsequently adding the dependency "socket.io": "^2.1.1"
in my package.json, and ran the command npm install
to update my dependencies but still encounter the error.
As you can tell, I'm rather puzzled by this... especially after following the docs almost exactly here so any help is thoroughly appreciated!
This did the trick on my side:
var io = require('socket.io')(server, { serveClient: false })
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With