所以我正在将我的文件移动到node-webkit,并且使用socket.io,问题是...
在我的localhost上测试一切正常,但是当我把它移到node-webkit时,我得到
ReferenceError: io is not defined以下是我的文件:
Package.json
{
"name": "Editme",
"main": "index.html",
"window": {
"show": true,
"position": "center",
"width": 500,
"height": 500,
"toolbar": false,
"resizable": false
}
}Index.html
<html>
<head>
<title>OrbitMMO</title>
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script type="text/javascript" src="game/game.js"></script>
<script type="text/javascript" src="game/canvasengine-1.3.2.all.min.js"></script>
<link rel="stylesheet" type="text/css" href="game/style.css">
</head>
<body>
<div id="login">
<input type="text" id="name" />
<input type="password" id="password" />
<input type="submit" id="submit" />
</div>
<canvas id="canvas_game" width="600px" height="700px" >
</canvas>
</body>
</html>Game.js
var documentLoaded = setInterval(function() {
if(document.readyState === "complete")
{
clearInterval(documentLoaded);
startClient();
}
}, 5);
function startClient()
{
var socket = io('http://localhost');
}在我的index.html的同一文件夹中,我有我的服务器的node-modules文件夹的一个副本。所以我真的不知道为什么它不工作,而它是在本地主机上…
发布于 2014-12-26 03:27:45
您的package.json应该包含所有模块本身。您可以手动编辑该文件,也可以重新安装npm模块,以--save结尾,即npm install socket.io --save
发布于 2015-01-03 18:23:54
我也遇到了类似的问题,但是我使用node require来加载socket.io。我的解决方案是需要socket.io-client (npm的独立版本)。我不确定这会不会对你有帮助,但我想我还是会发帖的..
https://stackoverflow.com/questions/27649619
复制相似问题