socket.io - ReferenceError: io is not defined socket.io - ReferenceError: io is not defined android android

socket.io - ReferenceError: io is not defined


I found the answer for anyone who gets immensely confused by the horrible lack of documentation of socket.io.

You cannot source /socket-lib/socket.io.js,

you must source http://yourwebsite.com:12345/socket.io/socket.io.js.

The server automatically does the rest for you.


I solved it myself by changing index.html to import the socket io client from bower, first i installed the bower component:

 bower install socket.io-client

then i changed the reference in index.html to :

 <script src="bower_components/socket.io-client/socket.io.js"></script>

Or file could be found at - lib/socket.io-client/dist/socket.io.js


I managed to blunder through this, and squandered about an hour, on something that turned out to be a very basic error.

When an function is not defined? Such as " Uncaught ReferenceError: io is not defined ". Does that not mean that the function is getting "used" before it is "created"?

In the part of my HTML file, that "calls" the javaScript files, it looked like this :

<script src='./js/playerChatter.js'></script> <!-- this one calls io --><script src="http://localhost:2019/socket.io/socket.io.js"></script><!-- This Creates io -->

and i changed it to this

<script src="http://localhost:2019/socket.io/socket.io.js"></script> <!-- This Creates  io --><script src='./js/playerChatter.js'></script> <!-- this on calls io -->

So now the item "io", whether it is an object or function... Is actually getting created before it is getting used :D

Have FUN!