简体   繁体   中英

“window is not defined” error on Meteor Todo tutorial with Angular2

I want to get started with Meteor using Angular2. So I followed the official Meteor tutorial for a simple Todo App until step 2.7 where a new project is created, with Angular as template engine instead of the default blaze from Meteor.

I EXACTLY followed the steps in the tutorial 3 times, each time with a new project. But It seems impossible to get it work! When I start the application, I got the following error:

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

It seems that the server try to access the window object, which exists on the client only I think. But as a newbie, I have no clue why this happens, and what I have to do here, since the tutorial doesn't seem to have any information for this issue.

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

11.6 Prepare the component for each test imports/components/todosList/ client /todosList.tests.js »

So @blueren is correct, the tutorials aren't that clear on emphasizing the importance of folder structure

Once I created a client folder and directed it there, it ran correctly (answering this old question because I ran into this myself in 2021)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM