create-react-app的开发服务器不会自动刷新 [英] Development server of create-react-app does not auto refresh
问题描述
我正在使用create-react-app关注React的教程。
该应用程序由 create-react-app v1.3.0创建
I am following a tutorial on React using create-react-app. The application is created by create-react-app v1.3.0
create-react-app my-app
开发服务器由
npm start
多次更改代码后,浏览器不会更新实时/热重新加载更改。刷新浏览器没有帮助。只停止开发服务器并重新启动它才能捕获对代码的新更改。
After changing the code several times, the browser is not updated live / hot reload with the changes. Refreshing the browser does not help. Only stopping the dev server and starting it over again capture the new changes to the code.
推荐答案
您是否看过疑难解答用户指南的部分?
它描述了此问题的几个常见原因:
Have you seen the "Troubleshooting" section of the User Guide?
It describes a few common causes of this problem:
当
npm start
正在运行时保存文件时,浏览器应刷新更新的代码。
When you save a file while
npm start
is running, the browser should refresh with the updated code.
如果没有发生这种情况,请尝试以下解决方法之一:
If this doesn’t happen, try one of the following workarounds:
- 如果您的项目位于Dropbox文件夹中,请尝试移动
- 如果观察者没有看到名为
index.js
的文件,并且您正在通过文件夹名称引用它,你由于Webpack错误,需要重新启动观察者。 - 像Vim和IntelliJ这样的编辑有一个安全写入功能,目前打破观察者。你需要禁用它。按照中的说明进行操作使用支持安全写入的编辑器。
- 如果项目路径包含括号,请尝试将项目移动到没有它们的路径。这是由 Webpack观察者错误引起的。
- 在Linux和macOS上,您可能需要调整系统设置允许更多的观察者。
- 如果项目在虚拟机内运行,例如(一个Vagrant配置的)VirtualBox,则创建一个
.env
如果项目目录中不存在该文件,则将CHOKIDAR_USEPOLLING = true
添加到其中。这确保了下次运行npm start
时,观察者会在VM内部根据需要使用轮询模式。
- If your project is in a Dropbox folder, try moving it out.
- 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. - Some editors like Vim and IntelliJ have a "safe write" feature that currently breaks the watcher. You will need to disable it. Follow the instructions in "Working with editors supporting safe write".
- If your project path contains parentheses, try moving the project to a path without them. This is caused by a Webpack watcher bug.
- On Linux and macOS, you might need to tweak system settings to allow more watchers.
- 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 addCHOKIDAR_USEPOLLING=true
to it. This ensures that the next time you runnpm start
, the watcher uses the polling mode, as necessary inside a VM.
如果这些解决方案都没有帮助请发表评论在这个主题中。
If none of these solutions help please leave a comment in this thread.
我希望这会有所帮助!
这篇关于create-react-app的开发服务器不会自动刷新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!