使用Angular2的Meteor Todo教程中的“窗口未定义”错误

时间:2017-08-26 16:11:41

标签: javascript angular meteor

我想使用Angular2开始使用Meteor。所以我按照official Meteor tutorial for a simple Todo App直到步骤2.7创建了一个新项目,其中Angular作为模板引擎而不是Meteor的默认大火。

我完全按照教程中的步骤进行了3次,每次都有一个新项目。但似乎不可能让它发挥作用!当我启动应用程序时,出现以下错误:

C:\Users\MyUser\WebstormProjects\my-meteor-project2>meteor
[[[[[ C:\Users\MyUser\WebstormProjects\my-meteor-project2 ]]]]]

=> Started proxy.
=> Started MongoDB.
W20170826-17:58:26.182(2)? (STDERR) C:\Users\MyUser\AppData\Local\.meteor\packages\meteor-tool\1.5.1\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:280
W20170826-17:58:26.261(2)? (STDERR)                                             throw(ex);
W20170826-17:58:26.264(2)? (STDERR)                                             ^
W20170826-17:58:26.265(2)? (STDERR)
W20170826-17:58:26.266(2)? (STDERR) ReferenceError: window is not defined
W20170826-17:58:26.267(2)? (STDERR)     at Object.<anonymous> (C:\Users\MyUser\WebstormProjects\my-meteor-project2\node_modules\angular\angular.js:33887:4)
W20170826-17:58:26.270(2)? (STDERR)     at Module._compile (module.js:409:26)
W20170826-17:58:26.272(2)? (STDERR)     at Object.Module._extensions..js (module.js:416:10)
W20170826-17:58:26.273(2)? (STDERR)     at Module.load (module.js:343:32)
W20170826-17:58:26.275(2)? (STDERR)     at Function.Module._load (module.js:300:12)
W20170826-17:58:26.276(2)? (STDERR)     at Module.require (module.js:353:17)
W20170826-17:58:26.277(2)? (STDERR)     at require (internal/module.js:12:17)
W20170826-17:58:26.279(2)? (STDERR)     at Object.<anonymous> (C:\Users\MyUser\WebstormProjects\my-meteor-project2\node_modules\angular\index.js:1:1)
W20170826-17:58:26.282(2)? (STDERR)     at Module._compile (module.js:409:26)
W20170826-17:58:26.283(2)? (STDERR)     at Object.Module._extensions..js (module.js:416:10)
=> Exited with code: 1

服务器似乎试图访问window对象,我认为只存在于客户端上。但作为一个新手,我不知道为什么会发生这种情况,以及我必须在这里做什么,因为教程似乎没有任何关于这个问题的信息。

1 个答案:

答案 0 :(得分:0)

https://www.meteor.com/tutorials/angular/testing

<块引用>

11.6 为每个测试准备组件imports/components/todosList/client/todosList.tests.js »

所以@blueren 是正确的,教程并没有那么清楚地强调文件夹结构的重要性

一旦我创建了一个客户端文件夹并将其定向到那里,它就可以正确运行 (回答这个老问题是因为我自己在 2021 年遇到了这个问题)