Websocket unable to connect (using webpack-dev-server js file)


Hi everyone!

I’m writing an experimental app in electron and I’m using webpack as my build tool.
Everything works fine (the build runs correctly in electron and so on), the only issue I’m currently facing is with webpack-dev-server , specifically webpack-dev-server.js which tries opening a websocket connection but can’t find the url (/sockjs-node).

My guess is the problem is caused by electron because (maybe) I didn’t enable websocket protocol (using the protocol module), could that be the reason?

Feel free to point out that it’s a webpack issue, I’m not entirely sure of what I’m saying. I’m just looking for directions. Running the webpage in normal browser works with webpack-dev-server.js though. So my guess is that I’m dealing with something that it’s strictly connected to electron.

I’m still debugging the issue. One important note, I’m not running on file protocol, I’m running a registered protocol (named mdm) which I registered. It behaves like http, not like file protocol (didn’t add it to schemes), my feeling is that it’s trying to open a websocket using mdm:///sockjs-node instead of ws:// or http://

Anyone else managed to get webpack-dev-server working in electron and have some guidelines?


Hello, while in development, I use webpack-dev-server.js with React hot reload for my app and I did not do anything special.
My browser window’s index.html just looks like this :

    <meta charset="UTF-8">
	<script src="http://localhost:8080/webpack-dev-server.js"></script>    
    <script src="http://localhost:8080/app.js"></script>    


@dperetti in electron, are you serving through http, file protocol or a custom one?


Electron’s BrowserWindow simply loads the index.html with file protocol. But that index page loads the script from the webpack-dev-server that’s running on localhost.


Oh, here we go, looks like that’s the main thing. You include webpack-dev-server directly from url, I was doing an hacky thing through protocol and so when it used /sockjs-node as path, it tried using my protocol, which doesn’t support websocket.

Using directly http://localhost:8090/webpack-dev-server.js fixed the issue immediately