node.js 参考错误:窗口未定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11181562/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ReferenceError: window is not defined
提问by Alexander Farber
I'm trying to run the Pocket-Island game by Woogaand have installed all prerequisites listed at that page:
我正在尝试运行Wooga 的 Pocket-Island 游戏并安装了该页面上列出的所有先决条件:
gem install rake
npm install -g less
npm install -g jslint
...
And then build the program successfully by running
然后通过运行成功构建程序
rake all
And have now a new builddirectory:
现在有一个新build目录:
app.js css images index.html ipad.html templates version
The app.js is 400k and looks like a minimized JavaScript file.
app.js 大小为 400k,看起来像一个最小化的 JavaScript 文件。
Then I try to run it with node:
然后我尝试运行它node:
#node ./app.js
/home/afarber/src/Pocket-Island/build/app.js:1
window.wooga.cas
^
ReferenceError: window is not defined
at Object.<anonymous> (/home/afarber/src/Pocket-Island/build/app.js:1:63)
at Module._compile (module.js:446:26)
at Object..js (module.js:464:10)
at Module.load (module.js:353:31)
at Function._load (module.js:311:12)
at Array.0 (module.js:484:10)
at EventEmitter._tickCallback (node.js:190:38)
Being a complete node.jsnewbie, I suspect I'm missing something very obvious. Does anybody have an advice for me please?
作为一个完整的node.js新手,我怀疑我遗漏了一些非常明显的东西。有人对我有什么建议吗?
I've looked into app.js and there is no window.wooga.cas, but there are several following variables:
我查看了 app.js 并没有window.wooga.cas,但有以下几个变量:
window.wooga.castle.levels = .....
window.wooga.castle.entityDefinitions = .....
window.wooga.castle.version = "38da43a566503f3043576dafaf77f89363017397" ;
window.wooga.castle.tutorial = ....
So I think app.jsis ok, but I must install it somewhere or maybe tell it where to find standard libraries? (I've installed node.jsunder /usr/local/)
所以我认为没问题app.js,但我必须将它安装在某个地方,或者告诉它在哪里可以找到标准库?(我已经安装了node.js下/usr/local/)
I'm using a CentOS 6.2 and I'm actually an experienced Linux user.
我使用的是 CentOS 6.2,实际上我是一名经验丰富的 Linux 用户。
UPDATE:More info (not sure if helpful):
更新:更多信息(不确定是否有帮助):
# npm root
/home/afarber/src/Pocket-Island/build/node_modules
# npm --version
1.1.24
# node --version
v0.6.19
回答by user123444555621
node is used for building only, not for running the game. It looks like the build itself worked fine so far. The app.jsfie is to be loaded by index.htmlin a web browser.
节点仅用于构建,不用于运行游戏。到目前为止,构建本身似乎运行良好。该app.js文件将index.html在 Web 浏览器中加载。

