webpacker: Regression: Webpacker HMR causes SSR to fail in Webpacker 4+

https://github.com/reactjs/react-rails/issues/985

In webpacker 3 with HMR server side rendering worked for components marked “hot” In webpacker 4+

ExecJS::ProgramError in Adviser::AmlChecks#new
Showing app/views/welcome/index.html.erb where line #1 raised:
ReferenceError: window is not defined
(execjs):35:1
(execjs):24679:14
global ((execjs):1:102)
Object.<anonymous> ((execjs):1:120)
Module._compile (module.js:653:30)
Object.Module._extensions..js (module.js:664:10)
Module.load (module.js:566:32)
tryModuleLoad (module.js:506:12)
Function.Module._load (module.js:498:3)
Function.Module.runMain (module.js:694:10)

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (13 by maintainers)

Most upvoted comments

I’m having the same issue. I just update from webpacker 3.5 to 4 and having issue with window - ReferenceError: window is not defined

I’m going to be making a bunch of updates to react_on_rails very soon. We’ve got things working great with:

  1. SSR – Server Side Rendering
  2. Dynamic code splitting with SSR (that one is a bit tricky)
  3. HMR

I’m not clear on why there’s a connection with SSR and HMR.

With React on Rails, SSR is done by either

  1. Reading a bundle made just for SSR
  2. By hitting the webpack-dev-server and getting the same bundle the client uses.

I’ve never seen number 2, using the same bundle, in real production system as you can’t have animations, window, etc. used when rendering.

@jakeNiemiec I’m still running into this issue. I think either:

  1. This issue should be re-opened.
  2. We should open an issue in another library if the problem is there.

Starting in webpacker 4, something is referencing window without checking if it’s defined. I don’t have any idea where to look for that though.

Webpack sense. Didn’t know about the other one, or always assumed they were the same.