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

Thank's

Shmulik

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>"

Someone?

6 comments

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".

0

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.

Shmuel

0

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?
Thanks,
Sergey

0

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 "127.0.0.1:52048".

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"

Thanks

0

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.

Shmulik

0

You are welcome! Good luck in debugging.

0

Please sign in to leave a comment.