How to get a hot swap of a webpack module (reaction-hot-loader) that works when proxying your own socket.io server

I have a node express application that uses socket.io. This application is proxied through the webpack dev server, since I want to use the hot module replacement in the application to respond on the client side (which passes back the socket code in the node application).

If I add a listener socket.io, but it breaks the material to replace the hot module. I think because my listener receives messages instead of the hmr listener?

The problem is that when I save a file that will be hot, instead I get the following in the chrome dev and NO hot load tools:

[WDS] App updated. Recompiling...
client?eeaa:52 [WDS] Proxy error.
client?eeaa:54 cannot proxy to http://127.0.0.1:1338 (read ECONNRESET)
client?eeaa:90 [WDS] App hot update...
socket.io.js:1456 GET http://localhost:1339/socket.io/?EIO=3&transport=polling&t=LA7JXr9&sid=r1NFzh1HOD5GcbN0AAAA 502 (Bad Gateway)
client?eeaa:25 [WDS] App updated. Recompiling...
client?eeaa:90 [WDS] App hot update...
socket.io.js:1456 POST http://localhost:1339/socket.io/?EIO=3&transport=polling&t=LA7Jckl&sid=r1NFzh1HOD5GcbN0AAAA 400 (Bad Request)

(Body 400 (Bad Request):

{"code":1,"message":"Session ID unknown"}

Does anyone know how to properly configure this?

MY webpack.config.js :

var path    = require('path');
var webpack = require('webpack');

module.exports = {
  entry:  [
    'webpack-dev-server/client?http://127.0.0.1:1339/',
    'webpack/hot/only-dev-server',
    './src/client/main.js'
  ],
  output: {
    path:     path.join(__dirname, 'dist'),
    filename: 'client-bundle.js'
  },
  resolve: {
    modulesDirectories: ['node_modules'],
    extensions:         ['', '.js']
  },
  module: {
    loaders: [
      {
        test:    /\.js$/,
        exclude: /node_modules/,
        loaders: ['react-hot', 'babel']
      }, {
          test: /\.css$/,
          loader: 'style!css'
      }
    ]
  },
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new webpack.NoErrorsPlugin()
  ],
  devtool: 'inline-source-map',
  devServer: {
    hot: true,
    proxy: {
      '*': 'http://127.0.0.1:' + (process.env.PORT || 1338)
    },
    host: '127.0.0.1'
  }
};
+4

Source: https://habr.com/ru/post/1626307/


All Articles