`document is not defined` related to CustomEvents
See original GitHub issueI’m experiencing an odd issue… after a while of running my bankai server (generated by create-choo-app
version ^9.0.0-1
), I stopped it, and now I can’t start it back up.
First, I got an error about window
not being defined in the context of window.EventSource('sse')
.
Recognising this as part of choo-reload
, I disabled that plugin. Now I’m getting an error about document
not being defined in the context of document.createEvent
.
I’ve tried removing a bunch of my code, and reinstalling all dependencies, and I’m still getting the issue. Any idea why?
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (6 by maintainers)
Top Results From Across the Web
ReferenceError: document is not defined · Issue #472 - GitHub
I am getting an error for custom-event library which may be use for cross browser support. Angular universal does not support DOM related...
Read more >CustomEvent() - Web APIs | MDN
The CustomEvent() constructor creates a new CustomEvent object. ... An object that, in addition of the properties defined in Event() , can have...
Read more >ReferenceError: document is not defined (in plain JavaScript)
When you are using server side rendering there is no browser. Hence, there will not be any variable window or document . Hence...
Read more >Dispatching custom events - The Modern JavaScript Tutorial
We can not only assign handlers, but also generate events from ... Built-in event classes form a hierarchy, similar to DOM element classes....
Read more >Custom events in JavaScript: A complete guide
If the custom event has cancelable set to false , calling event.preventDefault() will not perform any action.
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 FreeTop 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
Top GitHub Comments
I spent the last couple of hours trying to debug an issue which I think is related to this ticket, but I’m not using
create-choo-app
, orbankai@next
.I did a fresh
npm install --save choo bankai
. This installschoo 6.0.0
andbankai 8.1.1
. I tried running the following block of code:bankai
crashes and returnsReferenceError: document is not defined
. Following the suggestion in this thread, I then ran the following block of code:Note: the same issue with the same fix will occur if you’re using
app.mount()
too.This code now works, but I’m still very confused as to why there has to be a
window
check even when usingbankai 8.1.1
which doesn’t seem to do anythingSSR
related.Is there a dependency that both
bankai 8.1.1
andbankai@next
are both using that has causedbankai 8.1.1
to break without awindow
check?This has me concerned because if you don’t do a
window
check (which isn’t mentioned in either thechoo
README or thebankai
README), your app breaks, and there’s no obvious explanation as to why. If you were a new user trying thechoo
/bankai
stack for the first time, I feel it would be somewhat confusing.Yeah I wasn’t calling that function; I just did create-choo-app. I think it’s being thrown by one of the deps?
Regarding SSR being enabled by default, is that relevant to people using bankai as a dev server, or is it an optimisation? I’ve personally not had to use SSR yet. I wouldn’t mind getting it as a free bonus, but it also means I don’t consider the implications of window being absent when I’m just throwing a basic UI together. So I wonder how we’d make that more clear, perhaps in the errors, or maybe make it so that if SSR fails the client code still runs rather than the whole app dying?