0

I am using server side rendering and while bundling the server file via webpack i am getting an error.

ReferenceError: window is not defined

I even tried faking a window object but it didn't work either.

I did this with no success

if (typeof window === "undefined") {
  global.window = {};
}

I also made sure i am only using window object inside componentDidMount.

Can anyone please help me out? Why i am getting this and how can i resolve it?

Sanjay Bisht
  • 86
  • 1
  • 7

1 Answers1

0

Do this

if (process.browser) {
  // client-side-only code will make sure that your code runs inside the browser
}
Scott Agirs
  • 599
  • 6
  • 14
  • Hey, @scott-agirs thanx for the response. But this is should do where and what should be inside the if? can you please elaborate? – Sanjay Bisht Jun 02 '19 at 19:27