简体   繁体   English

create-react-app 的开发服务器遇到 ESLINT 检测到的错误时停止自动刷新

[英]Development server of create-react-app stops auto refresh when meeting an error detected by ESLINT

I start React.js project in VS Code by我在 VS Code 中启动 React.js 项目

npm start npm启动

The development server of create-react-app stops when encountered an error by ESlint. create-react-app 的开发服务器在遇到 ESlint 错误时停止。 And when an error is fixed it never auto refresh the page.当错误得到修复时,它永远不会自动刷新页面。 It is necessary to refresh browser's page manually by push refresh button or F5.需要通过按刷新按钮或 F5 手动刷新浏览器页面。

For example: if i remove some of the closing brackets (which is error by default, not configured by ESlint), the development server stops, but when i place back the bracket, the server automatically refresh the page.例如:如果我删除了一些右括号(默认情况下是错误的,不是由 ESlint 配置的),开发服务器会停止,但是当我放回括号时,服务器会自动刷新页面。 But when the error is defined by ESlint (for example "no-trailing-spaces") the development server stops and after fixing the errors it never refresh the page..但是当错误由 ESlint 定义时(例如“no-trailing-spaces”),开发服务器停止并且在修复错误之后它永远不会刷新页面..

Here are the results in pictures:以下是图片中的结果:
the server stops when encountered an error by ESlint服务器在遇到 ESlint 错误时停止

after the errors are fixed, the server still show error and never refresh automatically修复错误后,服务器仍然显示错误并且永远不会自动刷新

ps Actually the server refresh ONLY one time on the first fixed error, On every following fixed error, the server never refreshing! ps 实际上服务器只在第一个固定错误上刷新一次,在每个以下固定错误上,服务器永远不会刷新!

Is there are any way to fix this problem?有什么办法可以解决这个问题吗?

Many thanks!非常感谢!


If this doesn't happen, try one of the following workarounds:如果这没有发生,请尝试以下解决方法之一:

  • If your project is in a Dropbox folder, try moving it out.如果您的项目位于 Dropbox 文件夹中,请尝试将其移出。
  • If the watcher doesn't see a file called index.js and you're referencing it by the folder name, you need to restart the watcher due to a Webpack bug.如果观察者没有看到名为 index.js 的文件并且您通过文件夹名称引用它,则由于 Webpack 错误,您需要重新启动观察者
  • Some editors like Vim and IntelliJ have a “safe write” feature that currently breaks the watcher. Vim 和 IntelliJ 等编辑器有一个“安全写入”功能,目前会破坏观察者。 You will need to disable it.您将需要禁用它。 Follow the instructions in “ Disabling swap files creation in vim ”.按照“ 在 vim 中禁用交换文件创建”中的说明进行操作。
  • If your project path contains parentheses, try moving the project to a path without them.如果您的项目路径包含括号,请尝试将项目移动到没有括号的路径。 This is caused by a Webpack watcher bug .这是由Webpack 观察程序错误引起的。
  • On Linux and macOS, you might need to tweak system settings to allow more watchers.在 Linux 和 macOS 上,您可能需要调整系统设置以允许更多观察者。
  • If the project runs inside a virtual machine such as (a Vagrant provisioned) VirtualBox, create an.env file in your project directory if it doesn't exist, and add CHOKIDAR_USEPOLLING=true to it.如果项目在虚拟机中运行,例如(已配置的 Vagrant)VirtualBox,请在项目目录中创建一个 .env 文件(如果它不存在),并将 CHOKIDAR_USEPOLLING=true 添加到其中。 This ensures that the next time you run npm start, the watcher uses the polling mode, as necessary inside a VM.这可确保下次您运行 npm start 时,观察者会根据需要在 VM 内使用轮询模式。

It turned out that the problem is not related with ESlint, but with react-scripts version.原来问题与 ESlint 无关,而与 react-scripts 版本有关。

Sadly, it took me several days to figure out from where the problem is coming.可悲的是,我花了几天时间才弄清楚问题出在哪里。

First i was thinking that the problem was related with ESlint, but i was wrong.首先我认为这个问题与 ESlint 有关,但我错了。

The Development server doesn't refresh even without ESlint in the project.即使项目中没有 ESlint,开发服务器也不会刷新。

After my research i found that the problem comes from react-script versions 4.0.0 and 4.0.1.经过我的研究,我发现问题来自 react-script 版本 4.0.0 和 4.0.1。

The only one workaround at this moment (when react-script 4.0.1 is available and don't work) is to downgrade to react-script 3.4.4.目前唯一的解决方法(当 react-script 4.0.1 可用但不工作时)是降级到 react-script 3.4.4。

To achieve that i use following steps:为此,我使用以下步骤:

In the project folder:在项目文件夹中:

1. In "package.json" file change react-scrips version: "react-scripts": "3.4.4"

2. Delete "package-lock.json" file

3. Delete whole folder "node_modules"

4. In the Terminal: npm install

5. In the Terminal: npm start

After these steps, the Development server again refresh like a charm:)在这些步骤之后,开发服务器再次像魅力一样刷新:)

I want to note that the steps above must to work for people which use react-scripts 4.0.0 or 4.0.1 and had the refresh problems from the Development server.我想指出,上述步骤必须适用于使用 react-scripts 4.0.0 或 4.0.1 并且在开发服务器上出现刷新问题的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM