WickyNilliams / enquire.js

Awesome Media Queries in JavaScript
http://wicky.nillia.ms/enquire.js/
MIT License
3.63k stars 269 forks source link

making enquire.js compatible with nodejs for server-side rendering #129

Closed akiran closed 9 years ago

akiran commented 9 years ago

I created a mixin that wraps enquire.js to create responsive reactjs components. https://github.com/akiran/react-responsive-mixin

When enquire.js is imported on nodejs for server-side rendering, it is failing with error ReferenceError: window is not defined

I know this library is not supposed to be used in nodejs. But to build isomorphic apps this library should be compatible with nodejs.

Do you have any thoughts on overcoming this problem.

I also opened a question on stackoverflow http://stackoverflow.com/questions/28275775/how-to-handle-window-object-on-nodejs-for-server-side-rendering-of-reactjs-appli

WickyNilliams commented 9 years ago

Can't say I do, sorry. If you find a solution please report back :)

damassi commented 6 years ago

@akiran - not sure if you've arrived at a solution, but its easy enough to do something like

if (typeof window !== 'undefined') {
  const enquire = require('enquire')
} else {
  ... 
}