WSL: React hot reload not working for changes made in index.js

Environment

Windows build number: Microsoft Windows [Version 10.0.19042.630]
Your Distribution version: Ubuntu 20.04
Whether the issue is on WSL 2 and/or WSL 1: WSL2

Steps to reproduce

NodeJs version: v15.2.0 NPM version: 7.0.8

  1. Create a new react app using the following command: npx create-react-app test
  2. Open the newly created app in VSCode.
  3. Start the app by running the command: npm start
  4. Observe the app starts correctly.
  5. now make any text change in App.js and observe the changes are reflected on the UI.
  6. Now try to make any change in index.js(add a new paragraph or text), observe the changes are not reflected on the UI. now refresh the page manually observe the changes are reflected on the UI now.

Expected behavior

Changes made in index.js is not reflecting on the UI, hence hot reloading fails. For all other files, hot reload works just fine and changes are reflected on the UI, once code is successfully compiled.

Actual behavior

After making changes in index.js, the browser window doesn’t refresh and hence have to manually refresh the page to view the changes made in index.js.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 22 (4 by maintainers)

Most upvoted comments

Hi @gulshanmudgal is your project store on your Windows file system or inside of your Linux file system? (i.e: Is it in /mnt/c ? )

If it is in the Windows file system, I believe you’re running into the fact that the Plan 9 server in WSL 2 does not support file watching on Windows files. As a workaround I’d recommend you place your files into the Linux file system (Plus you’ll get a performance boost!) Here’s our issue tracking this request: https://github.com/microsoft/WSL/issues/4739

I was having this same issue, until I created a .env file in my project and added CHOKIDAR_USEPOLLING=true, as WLS2 seems to be treated as a VM so polling mode is necessary

Well, I’ve just had the same issue. Windows 10 + WSL 2. Here’s my question on StackOverflow https://stackoverflow.com/questions/70536493/hot-reloading-page-in-react-17-0-2-within-a-container-doesnt-work

The thing is… you just have to move your project to \wsl$\Ubuntu-20.04\home<USERNAME>\YOURPROJECT

I’m using Git bash for Windows but had been facing the same problem. And this is how I solve it with React 17.0.1 https://stackoverflow.com/a/65543913/13285338. You can read advanced-configuration.md (url) in React’s docs to learn what it does. After that remember to rerun npm start

@craigloewen-msft With the same issue as OP explained, for me, the problem was with React update. So it can be possible solution for others.

I’m getting the exact same behaviour and my files are within the Linux file system. As @gulshanmudgal has said for other files hot reloading works but when I edit index.js it does not hot reload requiring a manual refresh.

guys, you just needed to disable CORS

Hi @gulshanmudgal is your project store on your Windows file system or inside of your Linux file system? (i.e: Is it in /mnt/c ? )

If it is in the Windows file system, I believe you’re running into the fact that the Plan 9 server in WSL 2 does not support file watching on Windows files. As a workaround I’d recommend you place your files into the Linux file system (Plus you’ll get a performance boost!) Here’s our issue tracking this request: #4739

Work for me. Thx !

@hazartilirot I can’t seem to find the \wsl in my CLI, can you help with this? Thank you…

I may have misunderstood. I am running windows 10. I have docker running a container, and I am running a react 17.0.1 inside of that container. The files are on my windows machine, not the container.

Excuse me if this is basic, I am quite junior with all this.

I was having this same issue, until I created a .env file in my project and added CHOKIDAR_USEPOLLING=true, as WLS2 seems to be treated as a VM so polling mode is necessary

You hero, this worked for me 😃

My script react-scripts start works with last Windows build (19042.685), WSL2 and setting the right WSL version ton an existing version : wsl --set-version <distribution name> <versionNumber>

I’m able to use hot reload on other projects as well that aren’t gatsby based (like this calculator demo).

It seems like this error might be based on your project. The only other thing I could think of is something within the localhost relay, but I’m unable to repro this error. For the sanity of tracking errors on this Github page I’m going to mark this as closed since I can’t find any relevant error, but please reopen it if you can determine any specific repro steps, or @ me here so I can see it. Thanks for filing this!