browserify / http-browserify

node's http module, but for the browser
MIT License
244 stars 110 forks source link

no window object present #97

Closed ywen closed 8 years ago

ywen commented 8 years ago

Hi,

I use node-fetch in a reacts + rails project. I use https://github.com/shakacode/react_on_rails to glue between reactjs and Rails. Everything works fine except when I do server side rendering it complains the error "Encountered error "Error: no window object present" when prerendering".

I am willing to work a PR, just need some directions. Thanks!

The line that raise the error:

https://github.com/substack/http-browserify/blob/master/index.js#L54

patrykkopycinski commented 8 years ago

Hi @ywen, i'm not sure, but i think it may help you: https://github.com/webpack/react-starter/issues/37#issuecomment-104304128

ywen commented 8 years ago

By removing a unnecessary node-fetch import the problem is fixed. Thanks for your help!

17Damon commented 8 years ago

because server can not find window, you can use this

getInitialState() { return {windowWidth: (typeof window !== 'undefined')? window.innerWidth:undefined}; },