choojs / bankai

:station: - friendly web compiler
Apache License 2.0
1.09k stars 102 forks source link

Server Side Rendering Skipped due to error: window is not defined #515

Open EyalSi opened 5 years ago

EyalSi commented 5 years ago

I have a large app using choo.js and bankai. I'm trying to move from choo 6.0.0 to 6.13.0 & bankai 8.1.1 to 9.15.0 I'm getting the following error when running bankai build: node ./node_modules/bankai/bin.js build index.js

"Server Side Rendering Skipped due to error: window is not defined"

Does anyone have an idea why I'm getting this? everything is working, but wanted to know what is the problem...

laduke commented 5 years ago

for me, it was that I had a reference window in my choo entry point. (even trying to wrap it in like if (window) {...} )

blahah commented 5 years ago

this is such persistent issue for me - and clearly for others. I think this should be possible for bankai to handle automatically. Specifically I think it should be possible to make a browserify transform that detects calls to the browser-exclusive API and wraps them automatically in the necessary protection to allow server-side rendering.

Is there any reason not to do this?

blahah commented 5 years ago

Also - I really think this needs to be in the README. Bankai errors out with no obvious route to a solution on many of the standard browser libraries. @yoshuawuyts thoughts on documenting it until a better solution is in place?

edit - links to where others eloquently described the problem:

yoshuawuyts commented 5 years ago

@blahah PRs to document this would be very welcome. Possibly its own section in the readme, or else as part of a FAQ.