Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React create app hot reload is not always working on linux

I created a react application using create-react-app boilerplate, which seems to be very popular, hot reload some times updates when any of the files changes and some times not, seems like there is a minimum duration or something like that, I'm using Ubuntu, node version 7.0, the script in package.json is npm:'react-script start' what I am missing ?

like image 452
challenger Avatar asked Feb 03 '17 00:02

challenger


People also ask

Does react support hot reload?

React Hot Loader is a plugin that allows React components to be live reloaded without the loss of state. It works with Webpack and other bundlers that support both Hot Module Replacement (HMR) and Babel plugins.

How do I reload an app in react?

import React from 'react'; function App() { function refreshPage() { window. location. reload(false); } return ( <div> <button onClick={refreshPage}>Click to reload!


1 Answers

When npm start doesn’t detect changes, below are the common troubleshooting steps provided in the create-react-app documentation - link.

While an app is running with npm start and updating code in the editor should possibly refresh the broswer with the updated code. If this doesn’t happen, try one of the following workarounds:

  1. If the project files are directly synced to your local system from a cloud storage like Dropbox or Google Drive and you're trying to run the app in them directly, try moving it out.
  2. Due to Webpack bug, you may need to restart the watcher. If the watcher doesn’t detect the index.js and you’re referencing it by the folder name.
  3. Safe write feature in editors like Vim and IntelliJ currently breaks the watcher. You will need to disable it.
  4. Due to Webpack watcher bug, projects with path contains parentheses causes issue, try moving the project to a path without them. .
  5. To allow more watchers in Linux and macOS, you might need to tweak system settings.
  6. 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. This ensures that the next time you run npm start, the watcher uses the polling mode, as necessary inside a VM.
  7. Could try increasing max_users_watches- link

More references:

  • Issue Tracker 1
  • Troubleshooting webpack
  • Issue Tracker 2 - Webpack polling
like image 116
Keshan Nageswaran Avatar answered Oct 01 '22 01:10

Keshan Nageswaran