60frames / webpack-hot-server-middleware

:fire: Hot reload webpack bundles on the server
MIT License
324 stars 50 forks source link

Hangs when errors are thrown inside server bundle #72

Closed chacestew closed 6 years ago

chacestew commented 6 years ago

The middleware seems to hang with no output when my server bundle encounters an error. Only upon exiting the process does the error trace print to stddout.

Middleware implementation is standard:

const compiler = webpack([client, server]);
  app.use(
    webpackDevMiddleware(compiler, {
      noInfo: true,
      stats: {
        warnings: false,
        colors: true,
        timings: true
      },
      publicPath: client.output.publicPath
    })
  );
  app.use(webpackHotMiddleware(compiler.compilers[0], { path: '/__hmr' }));
  app.use(webpackHotServerMiddleware(compiler));

I can reproduce by throwing anywhere in the render/server bundle. Otherwise the middleware works normally. Is this a limitation or something I haven't configured correctly?

chacestew commented 6 years ago

This was due to my render function being async and not passing the error down the middleware chain. In case anyone ends up here with the same issue and a similar implementation, async-error-catcher provides an easily solution.

Thanks for the library!