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)具有安全写入"功能,目前该功能会破坏观察器.您将需要禁用它.按照在vim中禁用交换文件创建"中的说明进行操作.
- 如果您的项目路径包含括号,请尝试将项目移动到没有括号的路径.这是由 Webpack 观察程序错误引起的.
- 在 Linux 和 macOS 上,您可能需要调整系统设置 允许更多的观察者.
- 如果项目在虚拟机中运行,比如(一个 Vagrant 配置的)VirtualBox,如果它不存在,在你的项目目录中创建一个
.env
文件,并添加CHOKIDAR_USEPOLLING=真正的
.这可确保下次运行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 "Disabling swap files creation in vim".
- 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屋!