【问题标题】:React development server keep disconnecting and page gets refreshed on every disconnectReact 开发服务器保持断开连接,每次断开连接时页面都会刷新
【发布时间】:2019-01-28 09:29:56
【问题描述】:

服务器每隔 4-5 秒就会断开连接,这会导致页面刷新,尤其是在第一次渲染时会发生多次。

控制台有这个消息

The development server has disconnected.
Refresh the page if necessary.

这是我的 webpackDevServer.config.js

 module.exports = function(proxy, allowedHost) {
 return {
 disableHostCheck: !proxy ||
  process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true',
 compress: true,
 clientLogLevel: 'none',
 contentBase: paths.appPublic,
 watchContentBase: true,
 publicPath: config.output.publicPath,
 quiet: true,
 watchOptions: {
   ignored: /node_modules/,
 },
 https: protocol === 'https',
 host: host,
 overlay: false,
 historyApiFallback: {
   disableDotRule: true,
 },
 public: allowedHost,
 proxy,
 setup(app) {
   app.use(errorOverlayMiddleware());
   app.use(noopServiceWorkerMiddleware());
    },
   };
 }; 

要么我想完全停止实时重新加载,要么摆脱这个问题,这非常烦人。

【问题讨论】:

  • 您找到解决方案了吗?我在 mac 上遇到了这个确切的问题,即使在尝试按照文档创建的默认 my-app 时也是如此。

标签: javascript reactjs webpack create-react-app


【解决方案1】:

最近,我在将 react-scripts 更新到最新版本 3.3.0 后遇到了这个问题。我只是进入我的package.json 并将"react-scripts": "3.3.0" 更新为"react-scripts" : "3.2.0"

之后:

npm install
npm start

我不再看到这个问题。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-12
    • 1970-01-01
    • 2014-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-28
    • 2017-03-21
    相关资源
    最近更新 更多