Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WSL 2 , React not reloading with file changes?

I recently installed WSL 2 but when I create an app using create-react-app and use npm start the app is not reloaded when I edit some file. Am I missing something?

like image 476
julz oh Avatar asked Jan 23 '26 12:01

julz oh


1 Answers

In my experience, this occurs when your source is on a Windows drive (e.g. /mnt/c) since the driver that WSL uses for those drives doesn't yet support inotify. See this answer for more details on a related issue.

There are at least two possible solutions:

  • The recommended solution if you need WSL2 is to place your files on the ext4 root filesystem for WSL. E.g. somewhere under /home/, for instance. This has the added advantage of being much faster than the Windows drive.

  • Or you can convert your instance to WSL1, which does support inotify on the Windows drives, and is much faster when dealing with files there. You can also keep a WSL1 and a WSL2 copy around if you want. They both serve different purposes, but for most React/web development, I think you'll find WSL1 a better fit.

    You can back up your existing distribution with wsl --export <distroname> <filename.tar>, and then change to WSL1 with wsl --set-version <distroname> 1. Or you can re-import the backup as wsl --import <newDistroName> <directory> <filename.tar> --version 1.

  • Also, in my testing for that other answer, when running VSCode and running a watcher in the VSCode terminal, it seemed to work for me. I'm still suspicious this was a "false positive" of sorts, but you might want to give it a shot.

like image 160
NotTheDr01ds Avatar answered Jan 27 '26 02:01

NotTheDr01ds



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!