question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Issues working with Webpack Dev Middleware in server rendering environments

See original GitHub issue

Hey,

I’m not sure if this has to do with this Webpack plugin or with Webpack itself, with Webpack Dev Middleware and in general, I’m not even sure if this makes sense at all.

I’ve just spent two hours to get this really great plugin working in a custom Server Side Rendering environment that’s currently using Webpack Dev Middleware (WDM) as Webpack’s dev server and Webpack Hot Middleware (WHM) for HMR.

The issues I encountered:

  • While my actual server rendered application is served on localhost:8500, my WDM is running on port 8501, but the socket connection is always created for window.location.port and is not configurable (yet)
  • After I manually changed the port to 8501 in runtime/createSocket.js, it’s still not working. There’s an outgoing request to http://localhost:8501/sockjs-node/info?t=1579726105901 but it looks like WDM isn’t listening to a /socksjs-node/info route: Cannot GET /sockjs-node/info
  • POST /sockjs-node/213/kxx15upe/xhr_streaming also gives me a 404
  • Universal components that are also used on the server side fail because $RefreshSig$ is not defined, which seems obvious because they are only defined when we’re in a browser environment.:
ReferenceError: $RefreshSig$ is not defined
    at eval (webpack:///./src/shared/i18n/IntlProvider.tsx?:17:10)
    at Module../src/shared/i18n/IntlProvider.tsx (build/server/server.js:5202:1)

The last one makes sense but maybe we could just assign () => {} noops to global.$RefreshSig$ and global.$RefreshReg$?!

After all, I’m not really sure if this plugin does even make sense in universal rendering scenarios. If it does, I’d be happy to get some helpful hints how this could be integrated into my certainly little bit unusual but probably not that exotic setup.

// edit: current state of my implementation attempt can be found here: https://github.com/manuelbieh/react-ssr-setup/compare/feature/react-refresh

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:12 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
ianvieiracommented, Feb 10, 2020

I had the same problem with the $RefreshSig$, in the end, it was caused by the cache-loader. As my client build runs before the server one, my server was using the cached version to the client.

To avoid it, check if you have any cache that can be shared between the two compilers (as cache-loader or babel-loader cache).

4reactions
Ephemcommented, May 11, 2020

This was solved by the v0.3 release for me.

I use dev- and hot-middleware in a custom SSR-setup which previously did not work, but by following the Readme and using this config everything now works out of the box:

new ReactRefreshWebpackPlugin({
  overlay: {
    sockIntegration: 'whm',
  },
}),
Read more comments on GitHub >

github_iconTop Results From Across the Web

Webpack vs webpack-dev-server vs webpack ... - Stack Overflow
A common problem when using webpack-dev-server with node/express is that webpack-dev-server is a server, as is node/express . That makes this ...
Read more >
How I solved and debugged my Webpack issue through trial ...
I know that webpack-dev-server is in maintenance now, so I tried webpack-serve, but it seemed like source maps do not work with it...
Read more >
Adding a server-side rendering support for an existing React ...
When we start building our project, we always start being fine with client side rendering. However, there comes a time when we need...
Read more >
The best webpack configurations for React applications
npm i -D webpack webpack-cli webpack-dev-server html-webpack-plugin ... This will tell webpack which environment's configuration to run.
Read more >
ardatan:webpack-dev-middleware - Packosphere
You have to create a webpack.config.js file that has the compilation configurations for both client and server code. You are to free to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found