ReferenceError: document is not defined
See original GitHub issue- I’m submitting a …
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support request here, see note at the top of this template.
- What modules are related to this Issue?
- [ ] aspnetcore-engine
- [x] express-engine
- [ ] hapi-engine
-
Do you want to request a feature or report a bug? Bug.
-
What is the current behavior? When you try and enter your server bundle on localhost:4000 in the browser you get an error saying
ReferenceError: document is not defined
for one of my services which handles cookies. -
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem by creating a github repo.
Follow the story here, run the bundle and go to localhost:4000.
https://github.com/angular/angular-cli/wiki/stories-universal-rendering
-
What is the expected behavior? I expect the bundle to run and/or fail silently for this kind of error, or if there’s some kind of polyfill I can use.
-
What is the motivation / use case for changing the behavior? If I have a service which uses
document
how can I avoid this error for being thrown? It’s not like I can just exclude it from the server bundle because basically every module uses this service. -
Please tell us about your environment:
- Angular version: 4.4.6
- Browser: [all]
- Language: [all]
- OS: [all]
- Platform: [NodeJs]
Issue Analytics
- State:
- Created 6 years ago
- Comments:8
Please read the Universal “Gotchas” section of the README. It explains both why
document
isn’t available and how to check for the current platform to write conditional code.