Skip to content

webpack-dev-server 6.0 dropped support for SockJS #1014

Description

@rtm-ctrlz

Recent update of webpack-dev-server (6.0.0) removed support for SockJS — see the release notes.

First of all @pmmmwh/react-refresh-webpack-plugin 0.6.2 should not be installed with WDS-6 because of peer range (^4.8.0 || 5.x).

But if it is - the plugin raises an error:

ERROR  Failed to compile with 1 errors                                                         
error  in ./node_modules/@pmmmwh/react-refresh-webpack-plugin/sockets/WDSSocket.js
Module not found: Error: Package path ./client/clients/SockJSClient is exported from package
./node_modules/webpack-dev-server, but no valid target file was found
(see exports field in ./node_modules/webpack-dev-server/package.json)

The dev-server still works, but the plugin, or at least part of it, doesn't.

I'm not ready to make a full-featured pull request, but here is the diff that should solve the problem (but only for WDS-6):

diff --git a/node_modules/@pmmmwh/react-refresh-webpack-plugin/sockets/WDSSocket.js b/node_modules/@pmmmwh/react-refresh-webpack-plugin/sockets/WDSSocket.js
index 896d2a4..8e02be6 100644
--- a/node_modules/@pmmmwh/react-refresh-webpack-plugin/sockets/WDSSocket.js
+++ b/node_modules/@pmmmwh/react-refresh-webpack-plugin/sockets/WDSSocket.js
@@ -4,15 +4,12 @@
  * @returns {void}
  */
 function initWDSSocket(messageHandler) {
-  const { default: SockJSClient } = require('webpack-dev-server/client/clients/SockJSClient');
   const { default: WebSocketClient } = require('webpack-dev-server/client/clients/WebSocketClient');
   const { client } = require('webpack-dev-server/client/socket');
 
   /** @type {WebSocket} */
   let connection;
-  if (client instanceof SockJSClient) {
-    connection = client.sock;
-  } else if (client instanceof WebSocketClient) {
+  if (client instanceof WebSocketClient) {
     connection = client.client;
   } else {
     throw new Error('Failed to determine WDS client type');

Note that this also affects package.json: the webpack-dev-server peer range (^4.8.0 || 5.x) doesn't include 6.x, and sockjs-client is now an unused optional peer dependency. Both would need updating for proper WDS 6 support.

I've also tried a couple of variants that support both WDS 5 and 6, but none of them look good enough — you can check them in this gist.

This issue body was partially generated by patch-package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions