question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Uncaught TypeError: SocketClient is not a constructor

See original GitHub issue

I have tried for a long time to get the React Refresh Webpack plugin working! I am using my own custom configuration for webpack, not create-react-app. When I was using the overlay of create-react-app it was working as expected:

process.env.NODE_ENV = "development";
process.env.BABEL_ENV = process.env.NODE_ENV;

const webpack = require("webpack");
const common = require("./webpack.common");
const { merge } = require("webpack-merge");
const ReactRefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin");

const webpackDevClientEntry = require.resolve(
  "react-dev-utils/webpackHotDevClient"
);

const reactRefreshOverlayEntry = require.resolve(
  "react-dev-utils/refreshOverlayInterop"
);

module.exports = merge(common, {
  mode: "development",
  devtool: "source-map",
  plugins: [
    new webpack.HotModuleReplacementPlugin(),
    new ReactRefreshWebpackPlugin({
      overlay: {
        entry: webpackDevClientEntry,
        module: reactRefreshOverlayEntry
      }
    })
  ]
});

But after using new ReactRefreshWebpackPlugin() without options, I got this error in the browser console, my terminal (webpack compilation) has no error…

image

`

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
pmmmwhcommented, Aug 27, 2021

The solution is to get the urlParts from the configuration of webpack dev server client.webSocketURL option.

Support for this particular config would be added, maybe later this week, but is not there yet now. However you can override the options by using the overlay option of this plugin.

2reactions
MuhammadSawalhycommented, Aug 27, 2021

I think I’ve found what causes this issue:

image

it should be:

function initWDSSocket(messageHandler, resourceQuery) {
  if (typeof __webpack_dev_server_client__ !== 'undefined') {
-    const SocketClient = __webpack_dev_server_client__;
+    const SocketClient = __webpack_dev_server_client__.default;

    const urlParts = getSocketUrlParts(resourceQuery);
    const connection = new SocketClient(url.format(urlParts));
Read more comments on GitHub >

github_iconTop Results From Across the Web

'SocketClient is not a constructor' in react-refresh-webpack ...
I would use export default { instead of module.exports = {; You need to use the latest refresh plugin (0.5.0), explanation is in...
Read more >
Webpack使用ReactHMR时出现SocketClient is not a ...
Uncaught TypeError : SocketClient is not a constructor at initWDSSocket (build.js:2229:24). 1; 2. 在这里插入图片描述
Read more >
SocketClient is not a constructor 오류 - 인프런 | 질문 & 답변
RefreshWebpackPlugin = require("@pmmmwh/react-refresh-webpack-plugin"); ; devtool: "eval", resolve ; module: { rules: [ { test ...
Read more >
Laravel-mix error compile webpack.LoaderOptionsPlugin ...
c:\development\php\laravel\webpack.config.js:252 new webpack.LoaderOptionsPlugin({ ^ TypeError: webpack.LoaderOptionsPlugin is not a constructor at Object.
Read more >
Migrating from 2.x to 3.0
A v3 client is still not be able to connect to a v2 server though. ... Uncaught TypeError: packet.data is undefined.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found