create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

react-scripts 3.3.0 - "The development server has disconnected. Refresh the page if necessary"

Open elisciandrello opened this issue 6 years ago • 43 comments

So in development, just a standard create-react-app template, and I start receiving this console error right away.

I went through previous issues of this sort, followed all instructions but no matter what still ran into this error.

The only way I was able to prevent it from happening was downgrading to react-scripts-3.2.0

elisciandrello avatar Dec 18 '19 17:12 elisciandrello

Did you also see an error related to websockets in the console? This could be related to #8075 . The fix is merged (#8079) and will be released with 3.3.1. If you don't want to downgrade to 3.2.0, you can hack up line 62 from:

protocol: 'ws', to protocol: window.location.protocol === 'https:' ? 'wss' : 'ws',

in the following file: node_modules/react-dev-utils/webpackHotDevClient.js

noelstieglitz avatar Dec 20 '19 18:12 noelstieglitz

Unfortunately window.location.protocol === 'https:' ? 'wss' : 'ws' doesn't help. I'm running it on http://localhost anyway in docker with node_modules mounted as named volume with nginx as reversed proxy. It disconnects after about 1 min. react-scripts-3.2.0 works properly with my setup though

websash avatar Dec 24 '19 17:12 websash

Same for me, nginx reverse proxy for ssl, I have the window.location.protocol === 'https:' ? 'wss' : 'ws' line hacked in because I need https for development. But after about a minute idle, it disconnects. with this The development server has disconnected. Refresh the page if necessary. message.

My nginx config:

server {
  listen        80;
  server_name   xxx;
  return 301 https://$host$request_uri;
}

server {
  listen        443;
  server_name   xxx;

  location / {
    proxy_pass  http://192.168.42.211:3333;
  }

  location /api {
    proxy_pass  http://192.168.42.211:3030;
  }

  add_header Strict-Transport-Security    "max-age=31536000; includeSubDomains" always;
  add_header X-Frame-Options              SAMEORIGIN;
  add_header X-Content-Type-Options       nosniff;
  add_header X-XSS-Protection             "1; mode=block";

  proxy_set_header X-Real-IP           $remote_addr;
  proxy_set_header X-Forwarded-For     $proxy_add_x_forwarded_for;
  proxy_set_header X-Forwarded-Proto   $scheme;
  proxy_set_header Host                $host;
  proxy_set_header X-Forwarded-Host    $host;
  proxy_set_header X-Forwarded-Port    $server_port;
  proxy_set_header Upgrade $http_upgrade;
  proxy_set_header Connection "upgrade";

  ssl on;
  ssl_certificate             /etc/ssl/private/fullchain1.pem;
  ssl_certificate_key         /etc/ssl/private/privkey1.pem;
}

uncaught avatar Jan 02 '20 10:01 uncaught

After some digging I found that this is related to nginx's default proxy_read_timeout 60s rule. It seems that prior react-scripts versions would reload the websocket connection when it timed out after 60s.

Adding the following two rules to my location /sockjs-node fixed the disconnects for me when using an nginx reverse proxy - incidentally, CRA's built-in proxy does not have this disconnect issue.

    location /sockjs-node {
      proxy_pass http://client-web:3000;
      proxy_http_version 1.1;
      proxy_set_header Upgrade $http_upgrade;
      proxy_set_header Connection $connection_upgrade;

      # the following two timeout rules fix CRA WDS disconnects after 60s
      proxy_read_timeout 86400s;
      proxy_send_timeout 86400s;
    }

HTH

nazar avatar Jan 07 '20 14:01 nazar

Did you also see an error related to websockets in the console? This could be related to #8075 . The fix is merged (#8079) and will be released with 3.3.1. If you don't want to downgrade to 3.2.0, you can hack up line 62 from:

protocol: 'ws', to protocol: window.location.protocol === 'https:' ? 'wss' : 'ws',

in the following file: node_modules/react-dev-utils/webpackHotDevClient.js

I did attempt this and it actually still didn't work. The only way was downgrading my react-scripts still.

elisciandrello avatar Jan 07 '20 22:01 elisciandrello

This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs.

stale[bot] avatar Feb 06 '20 23:02 stale[bot]

I am still experiencing this issue, I've also ejected... not sure if anyone else is experiencing post eject..

bklynate avatar Feb 07 '20 04:02 bklynate

I can confirm this is still happening even in 3.3.1. Same as the comments above, I'm using a docker image to run the app in a reverse proxy with https enabled.

michaeljota avatar Feb 07 '20 21:02 michaeljota

Hello It's happening for me as well

omerfaran avatar Feb 09 '20 14:02 omerfaran

I looked at my package.json and it seems like my react-scripts version is 1.1.15, does it make sense? It's very old:

{
  "name": "ecommerce-react-graphql-stripe",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "axios": "^0.18.0",
    "gestalt": "^0.79.1",
    "react": "^16.4.2",
    "react-bootstrap": "^0.32.4",
    "react-datepicker": "^2.7.0",
    "react-dom": "^16.4.2",
    "react-redux": "^6.0.0",
    "react-router-dom": "^4.3.1",
    "react-scripts": "1.1.5",
    "react-spinners": "^0.4.5",
    "react-stripe-elements": "^2.0.1",
    "redux": "^4.0.1",
    "resize-base64": "^1.0.12",
    "strapi-email-sendgrid": "^3.0.0-alpha.14.5",
    "strapi-sdk-javascript": "^0.2.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

Should I upgrade to 3.2.0 then? Thanks in advance

omerfaran avatar Feb 09 '20 14:02 omerfaran

Confirm that setting proxy_send_timeout will solve the problem.

linhnn avatar Feb 11 '20 10:02 linhnn

Is there a simple way to set it via a patch in react-dev-utils ?

ArnaudBarre avatar Feb 11 '20 10:02 ArnaudBarre

Hey guys,

In case I'm not even using nginx could it be just related to using an old version of react-scripts?

From the answers here it seems that react-scripts 3.3.0 causes this, so I cannot understand the source of my problem.

The react web app is live, and a small percentage of users experience this disconnection problem.

Thanks in advance

omerfaran avatar Feb 11 '20 14:02 omerfaran

The react web app is live, and a small percentage of users experience this disconnection problem.

Are you serving the application live in production with "react-scripts start"? That's a development script and should not be used for production. Try to update react-script in package.json or follow a guide like https://create-react-app.dev/docs/updating-to-new-releases.

In any case, you should stop serving your application with this. Run a build and upload it to your server.

michaeljota avatar Feb 11 '20 16:02 michaeljota

Hello michaeljota thank you, yes, it's in production and I'm still serving it with "npm start". The reason is that I still implement changes and it's easier to update files without re-building the project. You think it might be the reason for this problem? Yes I will try to update react-scripts anyhow to see if it helps Thank you very much

omerfaran avatar Feb 12 '20 05:02 omerfaran

It would appear our setting to silence these messages stopped working in webpack some time recently: https://github.com/facebook/create-react-app/blob/8b0dd54c7a7488d46a43ff6d1c67a6b41c31feb1/packages/react-scripts/config/webpackDevServer.config.js#L49

Appears this is the same issue: https://github.com/webpack/webpack-dev-server/issues/2166. If someone could send a PR upstream to fix the issue, it'd be greatly appreciated!

ianschmitz avatar Feb 19 '20 05:02 ianschmitz

The problem is not the logging part, it's that after one minute you are disconnected from the dev server. It appears in 3.3, didn't try with 3.4 ATM

ArnaudBarre avatar Feb 19 '20 09:02 ArnaudBarre

Ah sorry i posted in the wrong issue. Meant to post in #8153. I was tired 😴

ianschmitz avatar Feb 19 '20 18:02 ianschmitz

Hi. I'm running npm start inside a kubernetes local development cluster behind a Kong ingress (which uses nginx under the hood) and have this problem with 3.3. Switched to 3.2 and problem is solved, but now don't have the lastest TS 3.7 features.

rhyek avatar Feb 19 '20 21:02 rhyek

I upgraded my react-scripts to 3.2.0. The problem was "solved" in a sense that that I don't see the message "server was disconnected" in the console. Yet, the exact problems still persist, the web app functions in a somewhat random fashion for 5% of the users, while for others everything is working fine.

All users use the most recent version of Google chrome, I cannot tell what causes those problems to only some of them

omerfaran avatar Feb 20 '20 08:02 omerfaran