Node: Socket io require.resolve is not a function?

I'm surprised that googling it doesn't give me any results. Anyway, here's my problem when using socket.io

:

enter image description here

When I check further, it was from socket.io's original index.js file (line 28) causing the problem:

var clientSource = read(require.resolve('socket.io-client/socket.io.js'), 'utf-8');

So require.resolve () is not a function, I suspect it was my version of node at first, but no, I have updated to the latest version and it still persists.

I am using browserify and gulp to create an application file.

Who has a fix? Thanks to

+3


source to share


2 answers


browserify

the implementation require

has no method resolve

.



for obvious reasons, you cannot run the server socket.io

inside a browser. If you really want a socket.io client you will need socket.io-client

(the readme says it is browser compatible).

+13


source


To use socket.io in a browser, install the client lib:

npm install socket.io-client --save

      



it can be imported with:

var io = require('socket.io-client');

      

+3


source







All Articles