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

1.13.0 [WS] Disconnected, net::ERR_CONNECTION_REFUSED #326

Closed
laszlokorte opened this issue Nov 25, 2015 · 33 comments
Closed

1.13.0 [WS] Disconnected, net::ERR_CONNECTION_REFUSED #326

laszlokorte opened this issue Nov 25, 2015 · 33 comments

Comments

@laszlokorte
Copy link

For versions greater than 1.12.1 The WebSocket connection seems to be broken.

In the console I get the errors:

GET http://localhost/info?t=1448470960512 net::ERR_CONNECTION_REFUSED
[WDS] Disconnected!

My Webpack Config looks like this:

{
//....
plugins: [
    new webpack.HotModuleReplacementPlugin(),
],
devServer: {
    contentBase: "./app/static",
    port: 3000,

    inline: true,
    historyApiFallback: true,

    colors: true,
    stats: 'normal',
},
}

As you can see the port is set to 3000 and I also access the page via http://localhost:3000/ but the WebSocket connections seems to ignore the port and tries to connect to http://localhost/info

I am new to webpack so I am not quite sure if I am doing something wrong but as it was working a few days ago and also works if I downgrade to 1.12.1 I suppose it's an error with webpack-dev-server.

@madjam002
Copy link

+1 I'm getting this issue too, 1.12.1 works fine.

@syranide
Copy link
Contributor

+1 Getting the same problem when going from 1.12.1 to 1.13.0. But I'm using the default port.

EDIT: Ok unrelated it seems, socket.io is now sockjs-node instead.

@laszlokorte
Copy link
Author

could be related to this one sockjs/sockjs-client#262

@SpaceK33z
Copy link
Member

I probably introduced this bug with PR #302. I am able to reproduce this bug using vagrant, so I'll look into it soon.

@carpeliam
Copy link

I'm seeing:

GET http://localhost:8124/sockjs-node/info?t=1448668134012 404 (Not Found)
[WDS] Disconnected!

after upgrading webpack-dev-server from v1.10.1 to v1.14.0. I'm using webpack-dev-server directly in node, via:

// ...
var bundler = new WebpackDevServer(webpack(webpackConfig), {
    publicPath: '/build/',
    inline: true,
    hot: true,
    quiet: false,
    noInfo: true,
    stats: {colors: true}
});

bundler.listen(3001, 'localhost');
// ...

I tried applying the changes in #328, and I'm still seeing the issue.

@SpaceK33z
Copy link
Member

@carpeliam, did you run npm run prepublish in the webpack-dev-server module after applying the changes in #328?

@laszlokorte
Copy link
Author

applying #328 fixed it for me. Thank you!

(after running npm run prepublish inside ./node_modules/webpack-dev-server/)

tommytroylin added a commit to tommytroylin/CommunityHealthMonitoringSystem that referenced this issue Nov 28, 2015
@sokra sokra closed this as completed in #328 Dec 3, 2015
@ghost
Copy link

ghost commented Dec 3, 2015

+1 on the fix with npm run prepublish. and for those trying to debug this on NPM v3.3.12, don't rely on locked version numbers in package.json (or even npm-shrinkwrap.json, for that matter) to put you back on WDS v0.12.1 if you're trying to downgrade.

@laszlokorte
Copy link
Author

When will there be a new release containing the fix for this?

@SpaceK33z
Copy link
Member

When @sokra has time for it I think ;).

@carpeliam
Copy link

@SpaceK33z finally had a chance to come back to this. Looks like it's working for others which is great, but I'm experiencing the same symptom (server logs say 15.12.18 08:10:16 404 GET /sockjs-node/info (Unknown - 1ms)). I completely reinstalled webpack-dev-server (removed the directory, installed webpack/webpack-dev-server#3d3c000df8889e8b557995e5fe918b29072c377f, and ran npm install && npm run prepublish within the webpack-dev-server directory).

Do I need to include an expicit dependency on sockjs and set up the server myself within my own app?

EDIT: I had webpack-dev-server listening to port 3001, setting up a proxy to my app running on port 8124. The requests to /sockjs-node/info were against my app port (8124), not my webpack-dev-server port (3001). Looks like proxying has changed since the version I was on previously (1.10.1), I'll look into how proxying is supposed to work now.

@savroff
Copy link

savroff commented Jan 13, 2016

Get this all the time. Hot reload works, but still get this

I think it's happens when I ugrade Google Chrome browser to v. 47.0.2526.106

@ThomWright
Copy link

v1.14.1 was released two days ago with this fix in it which is working for me. Have you upgraded to the latest version? If so, what you're seeing might be a different issue.

@timwingfield
Copy link

I just upgraded to v1.14.1 and am still seeing it.

image

Everything works fine, hot reload and the server, just this is constantly coming up in the console. About every 3 seconds.

@SpaceK33z
Copy link
Member

@timwingfield, the url should be /sockjs-node/info. Where does /assets/come from?

@timwingfield
Copy link

Good question, from my config I think.

entry: {
    App: [
      'webpack-dev-server/client?http://localhost:8080/assets/',
      'webpack/hot/only-dev-server',
      './client/javascripts/entry'
    ]
  },
  output: {
    path: path.join(__dirname, 'app', 'assets', 'javascripts'),
    filename: '[name]_wp_bundle.js',
    publicPath: 'http://localhost:8080/assets'
  },

@timwingfield
Copy link

@SpaceK33z upon more digging, I have a feeling Rails is the culprit here as it's configured to serve the web assets from /assets. Still looking. Thanks for pointing me in a new direction, though.

@timwingfield
Copy link

Nope, it was my webpack config.

changing the first line in the App array fixed it.
webpack-dev-server/client?http://localhost:8080/

@savroff
Copy link

savroff commented Jan 13, 2016

@timwingfield yes, we use under Rails. I fix it with changing config. Pretty much the same stuff, but I have multiply entries

module.exports = {
  context: __dirname,
  devtool: 'eval',
  entry: {
    'publisher': publisherEntries,
    'manager': managerEntries,
    'client': "webpack-dev-server/client?http://localhost:8080"
  },
  output: {
    path: __dirname + "/public/assets/build/",
    filename: "[name].js",
    publicPath: 'http://localhost:8080/'
  },
  plugins: plugins,
  module: {
    loaders: [
      { test: /\.js$/, loaders: ['react-hot', 'babel'], exclude: /node_modules/ }
    ]
  }

@timwingfield
Copy link

Got it all working now. Thanks @SpaceK33z and @savroff

@liamfd
Copy link

liamfd commented Feb 2, 2016

@timwingfield I'm having the same issue and attempted your fix. It got rid of the 404s, but, removing the /assets seems to break the actual hot reloading. It's giving me an error and it always refreshes the page. Are you experiencing that?
screen shot 2016-02-01 at 8 58 44 pm

edit: My apologies, adding the no errors plugin fixed it for me. For posterity:

plugins: [
    new webpack.NoErrorsPlugin()
],

Though this does seem kind of like a band-aid and not an actual fix, I don't know enough about that plugin to really say. It does seem to be working though.

@leedium
Copy link

leedium commented Feb 2, 2016

Hey dudes, getting a similar error, but not sure if it's my implementation or a configuration issue. Any help is appreciated.

  1. App served on localhost:3002/
    2 ) WDS/HMR bundles on localhost:3001
    3 ) Proxy set up on localhost:3000 to route html requests to localhost:3002, and js-bundle and websocket /upgrade requests to the WDS/HMR on 3001.

When I build I get the following error:

> [WDS] Disconnected!
sock.onclose @ client?e36c:70EventTarget.dispatchEvent @ eventtarget.js?a091:49(anonymous function) @ main.js?75ae:356
abstract-xhr.js?c9b2:128 
GET http://localhost:3001/sockjs-node/info?t=1454445244870 AbstractXHRObject._start @ abstract-xhr.js?c9b2:128(anonymous function) @ abstract-xhr.js?c9b2:21
app.html:1 
XMLHttpRequest cannot load http://localhost:3001/sockjs-node/info?t=1454445244870. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access. The response had HTTP status code 404.

I can't understand why this is because I have set this header value to * in the wpDevMiddleware config.
Any help would be appreciated. See configuration below. Not sure if I'm doing this right or if there is a better way

dev-middleware.js

let devMiddlewareOptions = {
        quiet:false,
        noInfo:true,
        hot:true,
        inline:true,
        lazy:false,
        publicPath: 'http://localhost:3001/',
        headers:{
            'Access-Control-Allow-Origin': '*'
        },
        stats:{
            colors:true
        }
    }
devServer.use(webpackDevMiddleware(bundler,devMiddlewareOptions))
devServer.use(webpackHotMiddleWare(bundler));

webpack-config.js

entry:{             
        app:[
             'webpack-dev-server/client?http://localhost:3001',
                 'webpack/hot/dev-server',
                  path.resolve(appPath, '../src/client.js')
                 ],
          },
    plugins:[
        new webpack.ProvidePlugin({riot: 'riot'}),
        new webpack.HotModuleReplacementPlugin(),
        new webpack.optimize.CommonsChunkPlugin({name:"globals" , filename: "build/scripts/globals.bundle.js"}),
    ]

@leedium
Copy link

leedium commented Feb 3, 2016

fixed:

webpack-config.js

    entry:{             
            app:[
                 //'webpack-dev-server/client?http://localhost:3001',
                 //'webpack/hot/dev-server',
                'webpack-hot-middleware/client?path=http://localhost:3001/__webpack_hmr',
                  path.resolve(appPath, '../src/client.js')
                 ],

@gertig
Copy link

gertig commented Feb 6, 2016

@timwingfield thanks for the tip on where to look!

I had
'webpack-dev-server/client?http://127.0.0.1:' + port
and needed to add a '/'
'webpack-dev-server/client?http://127.0.0.1:' + port + '/'

@sohkai
Copy link

sohkai commented Feb 18, 2016

@timwingfield Nice one, I was having exactly the same issue! I've updated the dev server wiki to reflect the need for the additional / at the end of the entry point.

youshengyouse pushed a commit to youshengyouse/doc_webpack that referenced this issue Mar 8, 2016
@Caldis
Copy link

Caldis commented May 30, 2016

Try to edit urlParts.hostname of sock = new SockJS() in

webpack-dev-server\client\index.js

Before

var newConnection = function() {
    sock = new SockJS(url.format({
        protocol: urlParts.protocol,
        auth: urlParts.auth,
        hostname: (urlParts.hostname === '0.0.0.0') ? window.location.hostname : urlParts.hostname,
        port: urlParts.port,
        pathname: urlParts.path === '/' ? "/sockjs-node" : urlParts.path
    }));

    sock.onclose = function() {
        console.error("[WDS] Disconnected!");

        // Try to reconnect.
        sock = null;
        setTimeout(function () {
            newConnection();
        }, 2000);
    };

    sock.onmessage = function(e) {
        // This assumes that all data sent via the websocket is JSON.
        var msg = JSON.parse(e.data);
        onSocketMsg[msg.type](msg.data);
    };
};

after

var newConnection = function() {
    sock = new SockJS(url.format({
        protocol: urlParts.protocol,
        auth: urlParts.auth,
        hostname: (urlParts.hostname === '0.0.0.0') ? window.location.hostname : '127.0.0.1',
        port: urlParts.port,
        pathname: urlParts.path === '/' ? "/sockjs-node" : urlParts.path
    }));

    sock.onclose = function() {
        console.error("[WDS] Disconnected!");

        // Try to reconnect.
        sock = null;
        setTimeout(function () {
            newConnection();
        }, 2000);
    };

    sock.onmessage = function(e) {
        // This assumes that all data sent via the websocket is JSON.
        var msg = JSON.parse(e.data);
        onSocketMsg[msg.type](msg.data);
    };
};

@dannguyen
Copy link

FWIW, @sohkai's fix doesn't seem to work when --content-base is provided as an argument,

e.g. given a project in which the source is in ./src, a package.json script might be configured as:

  "scripts": {
    "start": "webpack-dev-server --hot --inline --content-base src"
   }

@Jaikant
Copy link

Jaikant commented Jul 28, 2016

@leedium's fix worked for me. i.e. using webpack-hot-middleware instead of webpack-dev-server in the config file. But why is the question.

@danghatam
Copy link

thanks @leedium, it worked for me.

@jtarantinomastercard
Copy link

I have the same issue as @dannguyen. Updated to 1.16 and had to revert to 1.12 because the constant disconnects caused my browser to stall completely for 10 seconds roughly every 30 seconds. Any chance of a fix?

@AlexFrazer
Copy link

Did you make sure to use the same port in the devServer.port and webpack-dev-server/client?{url}?

@jtarantinomastercard
Copy link

@AlexFrazer yup!

wincent added a commit to wincent/masochist that referenced this issue May 12, 2017
@skesani
Copy link

skesani commented Sep 13, 2017

@timwingfield I am using angular-cli, i can't edit webpack config, do you know any other solution for angular-cli users?

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