Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I've followed the exact same steps which have always previously worked for me, create application through express, place the module dependencies in the node_modules folder. It appears that the socket.io client-side javascript file isn't being found.

(I've looked at other peoples fixes, which is to include the JavaScript file in a script tab. I have not had to do this for my previous node + socket.io projects).

JavaScript on client:

var socket = io.connect('http://localhost');

JavaScript on server:

var io = require('socket.io').listen(app);

node_modules folder:

socket.io, which has an internal node_modules folder containing socket.io-client

Error Message:

Uncaught ReferenceError: io is not defined
(anonymous function)

When I include the socket.io client manually: http://cdn.socket.io/stable/socket.io.js

I get a different error which is:

Uncaught TypeError: Object #<Object> has no method 'connect'
(anonymous function)
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
521 views
Welcome To Ask or Share your Answers For Others

1 Answer

On the client, did you do:

<script src="/socket.io/socket.io.js"></script>

before you set the socket variable?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...