socket.io, io is not defined (JS Error)

前端 未结 9 816
你的背包
你的背包 2021-01-03 20:33

I have just started with socket.io, its giving JS Error on client page

io is not defined

How to fix this ?

9条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-03 20:54

    If your server listening on port 3000 for example and your index.html connect on localhost:3000 then it will fail to include the local libraries on that port. To solve this problem, you should have already installed a normal server for example xampp and include the full url for your library to be served from xampp into your page for example : //localhost/my-project/node_modules/socket.... or just include it from cdn or use socket = io.connect('http://localhost:3000'); and load your page from normal server for example xampp

提交回复
热议问题