user2002495
user2002495

Reputation: 2146

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

I'm surprised that googling this does not 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 index.js source file (line 28) that's causing problem:

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

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

I'm using browserify and gulp to generate the app file.

Anyone has a a fix on this? Thanks

Upvotes: 3

Views: 2425

Answers (2)

Søren
Søren

Reputation: 23931

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

npm install socket.io-client --save

it can be imported with:

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

Upvotes: 3

vkurchatkin
vkurchatkin

Reputation: 13570

browserify implementation of require doesn't have resolve method.

for obvious reasons, you can't run socket.io server inside browser. If you really want a socket.io client, you should require socket.io-client (readme says it is browserify-compatible).

Upvotes: 13

Related Questions