window object can't be accessed when using Angular Universal
See original GitHub issueIssue Description
With angular universal/angular 4, app may be running in node enviroment. So, it requires server side implementation of log (got rid of ‘window’ object usage, etc):
EXCEPTION: Uncaught (in promise): ReferenceError: window is not defined ReferenceError: window is not defined at Logger.global (/Users/sergey/syst/msmev/redesign/angular/pgu/dist/server/index.js:43:24345) at new Logger (/Users/sergey/syst/msmev/redesign/angular/pgu/dist/server/index.js:43:24941) at MainModuleInjector.get [as _Logger_29] (/Users/sergey/syst/msmev/redesign/angular/pgu/dist/server/index.js:44:27364)
Issue Analytics
- State:
- Created 6 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
"Window is not defined" even when isPlatformBrowser used.
Set up a vanilla universal app and then add any angular module that references any non-angular JS module that makes a call to...
Read more >Can't access window objects in Angular 4 - Stack Overflow
Server Side Rendering is executed in a node environment, without access to DOM. That's the reason why you don't have access to document...
Read more >Angular Universal: ReferenceError: window is not defined
This error can be caused by a reference to the Window object if you are rendering your application from a server like Node.js....
Read more >Access Window, Document, LocalStorage in Angular Universal
How to access the Window object, the localStorage object and other browser types & global JS variables in Angular 5 with an Universal, ......
Read more >this - JavaScript | MDN
this ; Function context · function getThis ; Class context · class C ; Global context · // In web browsers, the window...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hi @wingsuitist,
I understand what you are saying but the logger is not responsible for getting logs from one place to another, its purpose is to log the messages wherever you configure it to. I do hope to create an appender that submits the messages to a rest endpoint to get the functionality that you are talking about but that’s something I haven’t seen any logger do so far.
However I believe @snrostov’s concern is not that he wants to see the messages in the server, its just that the module is not working correctly when Angular runs in the server using AoT since it accesses the “window” object, but Angular will only run some part of the code in the server not all of it, so some messages will end up appearing in the client and some others in the server, this is a separate issue that what you are referring to as you will still be getting some logs in the client only.
One more thing the client might not check the console.log, but you can access their server with your browser and check it yourself.
The main scenario this logger was built for was to log stuff in development and turn them off in production, however, a very common scenario is that you need a way to turn it back on in production through the browser and the way to do this is by exposing the logger config to the window so people can configure it using the browser’s console.
@wingsuitist I believe #137 is related to what you are talking about.