webpack-dev-server: sockjs-node ERR_CONNECTION_REFUSED when accessing from network
I get the following errors filling up my console log when accessing from either a virtual machine or a remote computer’s browser. Fortunately HMR still works correctly.
GET http://localhost:8080/sockjs-node/info?t=1456748942511 net::ERR_CONNECTION_REFUSED
AbstractXHRObject._start @ abstract-xhr.js:128
(anonymous function) @ abstract-xhr.js:21
[WDS] Disconnected!
sock.onclose @ client?4b5e:70
EventTarget.dispatchEvent @ eventtarget.js:49
(anonymous function) @ main.js:356

webpack.config.js
var path = require('path');
var node_modules = __dirname + '/node_modules'
var webpack = webpack = require('webpack');
var BrowserSyncPlugin = require('browser-sync-webpack-plugin');
var ExtractTextPlugin = require('extract-text-webpack-plugin');
var autoprefixer = require('autoprefixer');
var postcssImport = require('postcss-import');
var precss = require('precss');
var config = {
// Thanks Christian Alfoni: http://christianalfoni.github.io/javascript/2014/12/13/did-you-know-webpack-and-react-is-awesome.html#vendors
addVendor: function (name, path, loader) {
loader = loader || 0;
this.resolve.alias[name] = path;
this.module.loaders[loader].noParse.push(new RegExp(path));
},
entry: [
'webpack-dev-server/client?http://localhost:9090/',
'webpack/hot/only-dev-server',
path.resolve(__dirname, 'app/main.js')
],
output: {
path: path.resolve(__dirname, 'build'),
filename: 'bundle.js',
},
resolve: { alias: {} },
devServer: {
contentBase: 'build/'
},
module: {
loaders: [
{
noParse: [],
test: /\.jsx?$/,
loader: 'babel-loader',
query: {
presets: ['react', 'es2015']
}
},
{
test: /\.s?css$/,
loader: ExtractTextPlugin.extract('style-loader', 'css-loader?sourceMap&modules&importLoaders=1!postcss-loader')
}
]
},
postcss: function(webpack) {
return [
postcssImport({ addDependencyTo: webpack }),
precss,
autoprefixer
];
},
plugins: [
new BrowserSyncPlugin(
{
host: 'localhost',
port: 3000,
proxy: 'http://localhost:9090'
},
{
reload: false
}
),
// Set the name of the single CSS file here.
new ExtractTextPlugin('main.css', { allChunks: true }),
new webpack.HotModuleReplacementPlugin()
]
};
config.addVendor('jquery', node_modules + '/jquery/dist/jquery.min.js');
config.addVendor('marked', node_modules + '/marked/lib/marked.js');
module.exports = config;
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 9
- Comments: 48 (1 by maintainers)
Commits related to this issue
- Use localhost:8080 for webpack dev server https://github.com/webpack/webpack-dev-server/issues/416 — committed to annict/annict by shimbaco 5 years ago
- Fix for sockjs console errors https://github.com/webpack/webpack-dev-server/issues/416 — committed to GoogleCloudPlatform/datashare-toolkit by mservidio 4 years ago
- WIP: CDS UI Alpha v1 (#123) * Initial - migrated datasets page to updated API * dataset validation fix * account request migrations * account migrations * account updates * account fix... — committed to GoogleCloudPlatform/datashare-toolkit by mservidio 4 years ago
- fix https cert on localhost - chrome://flags/#allow-insecure-localhost - https://github.com/webpack/webpack-dev-server/issues/416#issuecomment-777021949 — committed to mismith/scotdance by deleted user 3 years ago
For all people with the same error. It will also occur if your server (webpack-dev-sever) is listening on another port (e.g. 8080) than in line
"webpack-dev-server/client?http://localhost:3000"Change the webpack.config.js to
or change the port in the correspoding line:
"webpack-dev-server/client?http://localhost:8080"to correct the port.Change this line:
'webpack-dev-server/client?http://localhost:9090/',to
'webpack-dev-server/client?http://' + require("os").hostname() + ':9090/',Thanks for pointing me in the right direction @sokra : I couldn’t get this to work, possibly due to using a Mac locally and connecting via a windows machine which was not resolving the hostname correctly. However putting the IP in worked correctly:
'webpack-dev-server/client?http://' + require("ip").address() + ':9191/',This is what worked for me:
Good Luck…
I have tried adding CORS headers to devServer to no avail:
I also has some issues using
'webpack-dev-server/client?http://' + require("os").hostname() + ':9090/',I expect using the IP as @mummybot suggested would work, but I just used
0.0.0.0.'webpack-dev-server/client?http://0.0.0.0:9090'since I am using
angular-clibased project. it useswebpackbut all the configurations are hidden from user. I mean I can’t findwebpack.config.jsso please help me@shtse8 I am not sure I understand your question correct.
You could change localhost or 127.0.0.1 to 0.0.0.0 in the devServer object in your webpack config.
Change the webpack.config.js to
and in the correspoding line:
webpack-dev-server/client?http://0.0.0.0:8080Turns out my issue was because I was running code on https and when I request something from webpack dev server it runs the socket code and uses whatever level of security is currently being used (in my case https). All I had to do was set https: true and it worked like a charm.
What i get is a stream of ERR_CONNECTION_RESET errors in the console when debugging in Chrome (ie, hot reload not working).
Now, my situation is that i’m running an ubuntu virtualbox guest, where the dev server is running, but trying to hit it from chrome running on the Windows host. Now certainly w/o doing anything else it won’t work (since localhost:3035 is the windows host, not the ubuntu guest), but typically what you do is setup port forwarding. Eg, i fwd localhost:3000 on the windows box to the guest no problem. I did the same for 3035, w/o doing that i was getting ERR_CONNECTION_REFUSED, but now i get ERR_CONNECTION_RESET.
Specifically, a curl on the ubuntu guest is fine:
But a curl on the windows host fails:
Somehow the dev-server is noticing “something” is amiss, but not sure how to fix it.
EDIT: Read up on some vagrant documentation (something similar to a vbox instance) and changed:
to
in the webpacker.yml file (i’m using Rails/Vue), and that did the trick. No more ERR_CONNECTION_RESET errors.
EDIT 2: With the latest version of vue cli: @vue/cli 4.4.5, this is how I fixed it: In package.json (no more webpack.config.js):
Yes, the double
--hostprops were necessary. The default port is 8080, but that was in use for me.@appsparkler thank you for your answers! I already solve the problem, I just update to a newer version and create the project from the beginning and the error is gone.
I have similar issue, but I get 404 instead of CONN refused. I am using dev middleware and hot middleware on express server to run the server. The page loads fine but the hot reload doesn’t work. When I save a change , webpack rebuilds but doesn’t automatically load the changes in the browser. webpack conifg:
server.js :
Any ideas?
@appsparkler 's reply was very helpful.
localhostdidn’t work for me but this did:It actually fixes both my problems: The issue I linked in the previous comment, where Electron tries to load
http://localhost:8080when it should loadhttp://127.0.0.1:8080, and also this error about sockjs-node not connecting.I have webpack dev server running behind a proxy locally. In the proxy config file I am forwarding all requests with
/webpackpath to the webpack dev server.When WDS tries to listen to the sock-js socket for HMR it is requesting
localhost.com/sockjs-node/info… will I need to forward these on to the WDS also?Just for future reference I was hitting 404 on this because I had:
'webpack-dev-server/client?0.0.0.0:9090'without the http://