Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Passing in hot: false does not disable HMR #85

Closed
heisian opened this issue Jan 24, 2018 · 4 comments
Closed

Passing in hot: false does not disable HMR #85

heisian opened this issue Jan 24, 2018 · 4 comments

Comments

@heisian
Copy link

heisian commented Jan 24, 2018

  • Node Version: v8.2.1
  • NPM Version: yarn v1.3.2
  • koa Version: v2.0.0-alpha.7
  • koa-wepback Version: ^2.0.3

If you have a large amount of code to share which demonstrates the problem you're experiencing, please provide a link to your
repository rather than pasting code. Otherwise, please paste relevant short snippets below.

// webpack.config.js
...
  devServer: {
    hot: false,
  },
...
// ./server/middleware/hotClient.js
const server = new Koa()
server.use(
  middleware({
    compiler,
    config: webpackConfig,
    dev: {
      logger: log,
      stats: 'minimal',
      publicPath,
      contentBase,
    },
    hot: {
      hot: false,
      // logLevel: 'silent',
    },
  })
)
server.listen(3000)

Expected Behavior

No websocket server should start.

Actual Behavior

Websocket server starts, and the client page tries to connect.

 NFO  Running [main]...
 CLI  Loading [development][main] environmental variables...
 NFO  Loaded environment variables are available in debug mode.
 NFO  Run yarn:run -i <webApp> to enable.
 CLI  Registering API with LocoProxy...
 CLI  Connected to DevOpz tunneler.
 CLI  Found host: MAIN_API_ROOT=https://xxx
 CLI  Registering CLIENT with LocoProxy...
 CLI  [nodemon] 1.14.11
 CLI  [nodemon] reading config ./nodemon.json
 CLI  [nodemon] to restart at any time, enter `rs`
 CLI  [nodemon] watching extensions: js,mjs,json
 CLI  [nodemon] starting `node -r babel-register -r babel-polyfill ./main/server/index.js`
 CLI  [nodemon] spawning
 CLI  [nodemon] child pid: 21760
 CLI  [nodemon] watching 396 files
 CLI  Connected to DevOpz tunneler.
 CLI  Found host: MAIN_API_ROOT=https://xxx
 CLI  Found host: MAIN_CLIENT_ROOT=https://xxx
 CLI  Found host: CLIENT_ROOT=https://xxx
 CLI  Starting webpack build...
ℹ 「hot」: webpack: Compiling...
✖ 「hot」: WebSocket Server Error { Error: listen EADDRINUSE 127.0.0.1:8081
    at Object.exports._errnoException (util.js:1024:11)
    at exports._exceptionWithHostPort (util.js:1047:20)
    at Server.setupListenHandle [as _listen2] (net.js:1319:14)
    at listenInCluster (net.js:1367:12)
    at GetAddrInfoReqWrap.doListen (net.js:1493:7)
    at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:97:10)
  code: 'EADDRINUSE',
  errno: 'EADDRINUSE',
  syscall: 'listen',
  address: '127.0.0.1',
  port: 8081 }
 CLI  Creating [main] server instance...
 CLI  Connected to MongoDB at mongodb://127.0.0.1/ethos
 CLI  [main] is ready and serving from port [8000].

The EADDRINUSE is irrelevant, of course, the server must still be running from a previously-killed process. However I would expect the server not to try to start at all.

How can we reproduce the behavior?

@shellscape
Copy link
Owner

shellscape commented Jan 24, 2018

Thanks for the issue but this isn't a problem with koa-webpack. Rather, this is an issue with webpack-hot-client.

You should also resolve this error:

「hot」: WebSocket Server Error { Error: listen EADDRINUSE 127.0.0.1:8081

It's very relevant, actually. If you have another socket server running off of different/other settings, it's going to mess up the instance you're trying to run. I'd recommend passing a different port to the hot settings, or making sure you're closing the koa-webpack middleware instance. The assumption that a separate instance of koa-webpack, and subsequently webpack-hot-client, wouldn't try to start a new socket server is a poor one - that's a core function of the module, and essential when running multiple instances.

Looking at webpack-hot-client, we can see that the module does actually disable HMR: https://github.com/webpack-contrib/webpack-hot-client/blob/master/lib/client/index.js#L31 in the traditional sense, and instead reloads the page should an update be detected. That's the behavior that the hot option dictates. If you wanted to disable full page reload, you'd have to use the reload: false option, which currently appears to be ignored. However, if you don't want any refresh when an HMR patch is detected, then you should use webpack-dev-middleware directly, as 50% of koa-webpack's usefulness is then moot.

@heisian
Copy link
Author

heisian commented Jan 25, 2018

Thanks for the reply. What I meant was that it seems the other server listening on 8081 must be an existing webpack-hot-clien websockets server that didnt get closed when I SIGINT’ed my previous run of the script.

At any rate you’re right, I should simply just use webpack-dev-middleware. Thank you for the advice and help.

@liubin915249126
Copy link

['dev'] is an invalid additional property? why?

@shellscape
Copy link
Owner

@liubin915249126 it's considered poor form to ask an off-topic question in an issue thread. Please do have a read about Github etiquette. Your question is what is called "thread jacking." Read the README, that's not a valid option.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants