Socket.IO - 未定义要求 [英] Socket.IO - require is not defined

查看:30
本文介绍了Socket.IO - 未定义要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让 socket.io 正常工作,但现在在 Chrome 中出现错误:

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

未捕获的 ReferenceError: require 未定义

client.php:9Uncaught ReferenceError: io is not defined

我改变了包含 socket.io.js 文件的方式,因为它不存在于其他地方:

I changed the way to include the socket.io.js file because it dosnt exists somewher else:

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

如果我尝试

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

我得到:加载资源失败:服务器响应状态为 404(未找到)

这是在 Ubuntu 上使用最新的一切

This is on Ubuntu with the latest of everything

我正在使用 http://socket.io/ 中的服务器代码在同一文件夹中使用像client.php一样有效,名为server.js,仅修改端口.

I'm using the server code from http://socket.io/ to work with in the same folder like client.php and that works, named server.js, only modified port.

推荐答案

如果您的脚本不是来自您的网络服务器,这将不起作用:

If your script isn't coming from your webserver, this will not work:

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

您必须明确说明主机和端口:

You have to explicitely state host and port:

<script src="http://localhost:<port>/socket.io/socket.io.js"></script>

这篇关于Socket.IO - 未定义要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆