【问题标题】:"window is not defined" error on Meteor Todo tutorial with Angular2使用 Angular2 的 Meteor Todo 教程出现“未定义窗口”错误
【发布时间】:2018-02-04 10:41:23
【问题描述】:

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

我完全按照教程中的步骤操作了 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 对象,我认为该对象仅存在于客户端上。但作为一个新手,我不知道为什么会发生这种情况,也不知道我必须在这里做什么,因为教程似乎没有关于这个问题的任何信息。

【问题讨论】:

  • 您当前的文件夹结构如何?如果您希望代码仅在客户端上运行,则将其放在名为客户端的目录中(例如 /client/index.js)或将代码包装在 if(Meteor.isClient){...} 块中
  • @blueren 和这里描述的一样:meteor.com/tutorials/angular/creating-an-app 我把imports 目录放在了根文件夹里。根据教程中的描述,这似乎是正确的。还是必须放在client 目录下?

标签: javascript angular meteor


【解决方案1】:

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

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

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

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

【讨论】:

    猜你喜欢
    • 2019-12-02
    • 1970-01-01
    • 2015-08-07
    • 1970-01-01
    • 2018-11-02
    • 2016-06-23
    • 2019-05-20
    • 1970-01-01
    • 2017-04-01
    相关资源
    最近更新 更多