I'd config and start my local webpackDevServer-based react project, it shows well on browser page ,but when I opened my dev-tools ,it just continuously console out the below errors, apparently,webpackDevServer is disconnect and reconnect again and again.
WebSocketClient.js:13 WebSocket connection to 'ws://localhost:3003/ws' failed: [webpack-dev-server] Event {isTrusted: true, type: 'error', target: WebSocket, currentTarget: WebSocket, eventPhase: 2, …} console error info image
And my local config info is as below.
webpack.config.dev.js
const path = require('path');
const paths = require('./paths.js');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
mode: 'development',
entry: {
index: './src/index.js',
},
devServer:{
port: 3003
},
output: {
filename: '[name].bundle.js',
},
devtool: 'inline-source-map',
module: {
rules: [
{
test: /\.m?js$/,
exclude: /(node_modules|bower_components)/,
use: {
loader: 'babel-loader',
options: {
presets: ['@babel/preset-env']
}
}
}
]
},
plugins: [
new HtmlWebpackPlugin({
title: 'Development',
template: paths.appHtml
}),
]
};
start.js
"use strict";
const Webpack = require("webpack");
const WebpackDevServer = require('webpack-dev-server');
const webpackConfig = require("../config/webpack.config.dev");
const compiler = Webpack(webpackConfig);
const devServerOptions = { ...webpackConfig.devServer, open: true };
const server = new WebpackDevServer(devServerOptions, compiler);
server.startCallback(() => {
console.log('Successfully started server on http://localhost:3003');
});
package.json->scripts
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"build": "node ./scripts/build.js",
"start": "node ./scripts/start.js"
}
I'd config the devServer port as 3003 aleady.
could any guys please give me some instructions how to solve this issue? Really looking forward to your answer!
Try to configure the devServer.host properly. This worked for my case.
devServer: {
port: 3003,
host: "127.0.0.1" // <-- this
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With