8

I am trying to run a simple webpack-dev-server that compiles .bundle.js files when they are requested if relevant source JavaScript files have changed. I do not want to enable Hot Module Replacement (HMR) at this time.

I have the server working, but it prints the following errors to the JavaScript console:

GET https://monkey.transposit.com:3000/sockjs-node/info?t=1486581439029 net::ERR_CONNECTION_CLOSED
    AbstractXHRObject._start @ home.bundle.js:3182
    (anonymous) @ home.bundle.js:3071
[WDS] Disconnected!
    log @ home.bundle.js:3684
    close @ home.bundle.js:3753
    sock.onclose @ home.bundle.js:3980
    EventTarget.dispatchEvent @ home.bundle.js:2917
    (anonymous) @ home.bundle.js:6021
GET https://monkey.transposit.com:3000/sockjs-node/info?t=1486581439029 net::ERR_CONNECTION_CLOSED
    AbstractXHRObject._start @ home.bundle.js:3182
    (anonymous) @ home.bundle.js:3071
GET https://monkey.transposit.com:3000/sockjs-node/info?t=1486581440063 net::ERR_CONNECTION_CLOSED
    AbstractXHRObject._start @ home.bundle.js:3182
    (anonymous) @ home.bundle.js:3071

I'm unclear on what the browser is trying to do that I'm seeing these errors. (Especially since the bundles are being compiled and served successfully).

Here's my webpack.config.js:

const path = require('path');
module.exports = {
  entry: {
    project_console: './src/console/console',
    …
  },
  output: {
    filename: '[name].bundle.js',
    path: path.join(__dirname, 'dist'),
    publicPath: '/js/',
    library: '[name]',
    libraryTarget: 'var'
  },
  module: {
    rules: [
      {test: /\.js$/, use: ['babel-loader'], include: path.join(__dirname, 'src')},
      {test: /\.scss/, use: ['style-loader', 'css-loader', 'sass-loader']}
    ]
  },
  devServer: {
    host: '0.0.0.0',
    port: 3000,
    hot: false
  }
};

Here's my package.json:

{
  …
  "files": [
    "src/"
  ],
  "scripts": {
    "start": "webpack-dev-server”,
    …
  },
  "dependencies": {
    "react": "^15.4.2",
    "react-dom": "^15.4.2”,
    …
  },
  "devDependencies": {
    "webpack": "^2.2.1",
    "webpack-dev-server": "^2.3.0”,
    …
  }
  "babel": {
    "presets": [
      "es2015",
      "react"
    ]
  }
  …
}

Thank you for any help!

Jordan Place
  • 153
  • 1
  • 1
  • 7
  • Try setting `hot` to false: https://webpack.github.io/docs/webpack-dev-server.html#webpack-dev-server-cli – lux Feb 08 '17 at 19:41
  • 1
    @lux I have `hot` set to false in *devServer.hot* in *webpack.config.js*. Is that what you mean? – Jordan Place Feb 08 '17 at 20:36

3 Answers3

3

I added --no-line to my invocation of webpack-dev-server and this solved my issue.

Here's my package.json:

{
  "scripts": {
    "start": "webpack-dev-server --no-inline”,
    …
  }
}
Jordan Place
  • 153
  • 1
  • 1
  • 7
3

In order to disable HMR you need to add the following to your webpack config

{
  devServer: {
    hot: false, // disable HMR
  },
  plugins: [],
}

More here

Haseeb Anwar
  • 2,438
  • 19
  • 22
2

You can put hotreload=false anywhere in the query string, even #hotreload=false works.

You will still get:

[WDS] App updated. Recompiling...

in the console log, but the page won't actually reload.

This behavior is possibly subject to change. I just found it by searching for WDS in my vendor.js file and working backwards :-)

Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
  • 1
    In webpack 5: `webpack-dev-server-hot=false&webpack-dev-server-live-reload=false` in the query string ([WDS source](https://github.com/webpack/webpack-dev-server/blob/ef148ec1feb66d0f72457d0b2de853b76b06b3c9/client-src/utils/reloadApp.js#L26)). – Rescribet Oct 14 '21 at 07:24