Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[webpack] webpack-dev-server 4.0+ websocket disconnect and looping #5

Open
JoyMoch opened this issue Feb 25, 2022 · 0 comments
Open
Labels

Comments

@JoyMoch
Copy link
Owner

JoyMoch commented Feb 25, 2022

Recently, i am trying to update webpack from 4 to 5. with the webpack dev server update to v4+, development environment broken down.
phrase one errors as blow:

[webpack-dev-server] [HPM] Error occurred while proxying request 127.0.0.1:8001/ws to undefined [ECONNRESET] (https://nodejs.org/api/errors.html#errors_common_system_errors)

There are so many cases in github or StackOverflow but not solution for me. i searched the source code in node_modules with this error log and find this

// target is undefined when websocket errors

in http-proxy-middle.js
image
so it is a websocket error! like this

Error: socket hang up
    at connResetException (internal/errors.js:561:14)
    at Socket.socketCloseListener (_http_client.js:380:25)
    at Socket.emit (events.js:214:15)
    at TCP.<anonymous> (net.js:658:12) {
  code: 'ECONNRESET'

with ECONNRESET, i find that it mens socket fetch data fail or no response data. it is frustrating.
as the same time chrome 98 log websocket disconnected and try to reconnect and looping.

i guess there is a error about client to webpack server. the request is ws://xxx/ws in chrome devtools-network/ws. for my devserver proxy, there is a rule for request to my own nodejs server with socket.io.js

'/ws': {
  target: 'xxx'
}

yes, there is a mistake. webpack dev server's websocket request has been proxy to my own server. so change the rules to other.
anyway, avoid to webpack socket rules.

in webpack dev server v4.0+, webpack dev server request is ws://xxx/ws but in old version, request just like this ws://xx/socket-nodejs/xxx. It is a really break change!!

fix, done!

@JoyMoch JoyMoch added the wbepack label Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant