Uncaught ReferenceError: io is not defined

I'm having trouble debugging javascript project.

I'm trying to debug both server and client side locally at the same time.

I'm using Node, Express, and socket.io.

The main.js under the server runs OK in debug mode.

When I run the client I get an error :

" Uncaught ReferenceError: io is not defined         C:/Users/Shmulik/IdeaProjects/ch-12/public/index.html:55"

The code at this lie is:

"socket = io.connect(');"

At the beginning of the index.html file I have the code:

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

When I run the index.html in the browser without debugger it runs OK.

Please help



I found how to make this line work, but I don't understand why it works perfectly without the debugger.

Instead of: "<script src="/socket.io/socket.io.js"></script>"

I wrote the full path: "<script src="C:\\Users\\Shmulik\\IdeaProjects\\node_modules\\socket.io\\node_modules\\socket.io-client\\dist\\socket.io.js"></script>"


Comment actions Permalink

Since at the beginning of the index.html file you have the code:

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

It means that "index.html" and "/socket.io/socket.io.js" should be served by one and the same http server.

Most likely "index.html" and "/socket.io/socket.io.js" files should be served by your Node.js server.

So make sure that "index.html" file is served by your Node.js http server (i.e. browser tab url is started with "http://localhost...", not "C:\\Users\\...").

To debug index.html file that is served by your Node.js http server, start the server, create "JavaScript Remote" run configuration and specify there "URL to open".

Comment actions Permalink

Thank you Sergey,

I invoke the debugger by running "debug index.html", it opens the chrome browser in the url "htth://localhost/index.html", but as I wrote it doesn't recognize the socket.io.js unless I gives it the direct path.

I'm running the client and the server locally using  Intellij IDEA. I'm not using remote connection.


Comment actions Permalink

To diagnose the cause of the problem, please provide the following:
1) What is port of your Node.js http server?
2) Could you please specify action sequence of "debug index.html"? Do you right-click "index.html" and select there "Debug index.html"? Or something else?
3) Is "index.html" served by your Node.js http server?

Comment actions Permalink

I run the client and the server locally under Intellij.

First I invoke node main.js file by right-click on maim.js and select "Debug 'main.js'".

The debugger is connected to "".

In the console tab the result is:

"debugger listening on port 52048

info: socket.io started

debug: client authorized".

In main.js I have the code: " server.listen(80);"

second I invoke index file by right-click on index.html and select "Debug index.html'".

The debugger is :"Connected to JetBrains chrome Extension".

In the Console tab the result is:

" Uncaught ReferenceError: io is not defined         C:/Users/Shmulik/IdeaProjects/ch-12-Debug/public/index.html:55"


Comment actions Permalink

Thank you very much Sergey.

From your replay I finely understood what is wrong with the way I tried to debug.

First I must debug the client javascript in remote mode. I setup the run/debug configuration to javascript->remote and the url to http://localhost/index.html.

To invoke the debugger of the index I first choose it on the top toolbar and then run it.

Everything is OK now.


Comment actions Permalink

You are welcome! Good luck in debugging.


Please sign in to leave a comment.