[英]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:如果这没有发生,请尝试以下解决方法之一:
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.