Socket.IO - require is not defined

后端 未结 8 2158
Happy的楠姐
Happy的楠姐 2020-12-28 08:49

I\'m trying to get socket.io working but now in Chrome I get the error:

Uncaught ReferenceError: require is not defined

client.php:9

8条回答
  •  自闭症患者
    2020-12-28 09:09

    Are you running node.js along PHP on your server?

    There are two "socket.io" packages, a server and a client. You're trying to load the server one (/node_modules/socket.io/lib/socket.io.js) in the browser. The script you want is called socket.io-client and you can find it at https://raw.github.com/LearnBoost/socket.io-client/master/socket.io-client.js

    What happens is that socket.io automatically serves the /socket.io/socket.io.js (the client one) file from port 80 when you're running node on port 80. In your case Apache is already at port 80, so you need to serve the file from it manually.

提交回复
热议问题