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

Dev server crashes with react-scripts v4 #1705

Closed
varoot opened this issue Oct 27, 2020 · 7 comments
Closed

Dev server crashes with react-scripts v4 #1705

varoot opened this issue Oct 27, 2020 · 7 comments

Comments

@varoot
Copy link

varoot commented Oct 27, 2020

Current behavior

When running styleguidist server with react-scripts 4.0.0 and open in the browser, the server crashes with "Error: Already listening" message.

To reproduce

  1. Create a new project with latest CRA: yarn create react-app test
  2. Install Styleguidist yarn add -D react-styleguidist
  3. Run dev server and open the browser yarn styleguidist server --open

Demo repository:
https://github.com/varoot/styleguidist-example

Expected behavior

The dev server should run without crashing. User should be able to see the styleguide.

@rpeach
Copy link

rpeach commented Oct 29, 2020

Seems to be caused by the fast refresh changes in react-scripts/config/webpack.config.js

You can temporarily work around the error by setting an environment variable FAST_REFRESH=false

Something like this

cross-env FAST_REFRESH=false styleguidist server

@krsnaa
Copy link

krsnaa commented Oct 30, 2020

Alternatively, just include it in your package.json:

"scripts": { "styleguide": "FAST_REFRESH=false styleguidist server" }

@aniketkolekar-ms
Copy link

Temporary Fix:

  1. Install cross-env : npm install --save-dev cross-env
  2. Update script in package.json : "scripts": { "styleguide": "cross-env FAST_REFRESH=false styleguidist server" }
  3. Run : npm run styleguide

This worked for me. Auto-refresh working fine.

@poteirard
Copy link
Contributor

Maybe this is related facebook/create-react-app#9872 ?

@lyz810
Copy link

lyz810 commented Nov 13, 2020

I have the same problem,when upgrade to 11.1.2,and 11.1.1 has the same problem

I find react-dev-utils in package.json upgrade from ^9.1.0 to ^11.0.0

react-dev-utils@9.1.0 use sockjs-client, an react-dev-utils@11.0.0 use browser WebSocket directly
react-dev-utils@9.1.0:
https://github.com/facebook/create-react-app/blob/v3.2.0/packages/react-dev-utils/webpackHotDevClient.js#L61
react-dev-utils@11.0.0:
https://github.com/facebook/create-react-app/blob/v4.0.0/packages/react-dev-utils/webpackHotDevClient.js#L60

In Chrome network panel, the requests are different .
react-styleguidist@11.1.0(react-dev-utils@9.1.0):
image

react-styleguidist@11.1.2(react-dev-utils@11.0.0):
image

The selected websocket request in the second picture cause the webpack dev server crash
In old version, this request will not be send, so the server runs normally, However, when I type new WebSocket('ws://localhost:6060/sockjs-node') in Chrome console panel, the server crash with error message:

Error: read ECONNRESET
Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:205:27)
...

I'm not sure this bug is cause by react-dev-utils/webpackHotDevClient(should not send the /sockjs-node websocket connection), or by webpack-dev-server(should handle the connection correctly)

@lyz810
Copy link

lyz810 commented Nov 13, 2020

I have the same problem,when upgrade to 11.1.2,and 11.1.1 has the same problem

I find react-dev-utils in package.json upgrade from ^9.1.0 to ^11.0.0

react-dev-utils@9.1.0 use sockjs-client, an react-dev-utils@11.0.0 use browser WebSocket directly
react-dev-utils@9.1.0:
https://github.com/facebook/create-react-app/blob/v3.2.0/packages/react-dev-utils/webpackHotDevClient.js#L61
react-dev-utils@11.0.0:
https://github.com/facebook/create-react-app/blob/v4.0.0/packages/react-dev-utils/webpackHotDevClient.js#L60

In Chrome network panel, the requests are different .
react-styleguidist@11.1.0(react-dev-utils@9.1.0):
image

react-styleguidist@11.1.2(react-dev-utils@11.0.0):
image

The selected websocket request in the second picture cause the webpack dev server crash
In old version, this request will not be send, so the server runs normally, However, when I type new WebSocket('ws://localhost:6060/sockjs-node') in Chrome console panel, the server crash with error message:

Error: read ECONNRESET
Error: read ECONNRESET
    at TCP.onStreamRead (internal/stream_base_commons.js:205:27)
...

I'm not sure this bug is cause by react-dev-utils/webpackHotDevClient(should not send the /sockjs-node websocket connection), or by webpack-dev-server(should handle the connection correctly)

In this source code: https://github.com/webpack/webpack-dev-server/blob/89ffb86cd26425c59e3937ca06a2c804a01b8f1d/lib/utils/getSocketServerImplementation.js#L9

webpack-dev-server support two method: ws and sockjs by passing transportMode, if not given, use {server: 'sockjs', client:'sockjs'} as default

Since the latest version of webpackHotDevClient use WebSocket, so I think it should be passed by transportMode: { server: 'ws', client:'ws'}

// webpack.config.js
module.exports = {
    devServer: {
        transportMode: {
            server: 'ws',
            client: 'ws',
         },
     },
};

This worked for me.

@styleguidist-bot
Copy link
Collaborator

🎉 This issue has been resolved in version 11.1.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants