WSL: HRM not working on WSL 2
Please fill out the below information:
-
Microsoft Windows [version 10.0.18956.1000]
-
What you’re doing and what’s happening: Development frontend technologies with HRM (Hot Reload Module)
-
What’s wrong / what should be happening instead: HRM not working on WSL 2 using
localhost, but withnetwork ipworks.
This issues says that works.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 25
- Comments: 69 (6 by maintainers)
The only thing that solved it for me too was to move the project into a linux path and not sitting in my windows home path. I did also set the max_user_watches but that didn’t have any affect with HMR, moving to linux ~ (home) directory and running from there fixed it.
This is not a good solution given the benefits of WSL2, defeats the point of it all, for me anyways.
Ideally i should be able to store my project folders in my windows home folder and use linux for development and running of my services. I can then upgrade my linux distro, change distro even and not have to worry about losing my project files or re-cloning.
Nothing I tried worked. Finally, I decided to move my project files away from the windows file system into my Linux home directory. Wow, what a difference. Not only the file watchers started to work. The compilation speed was increased drastically (we are talking about from 1m to 5sec for
npm start).if you are using webpack-dev-server and wsl2, changes in windows do not trigger the dev-server. but you can use the --watch-poll option. “–watch-poll makes sure that webpack can detect changes in your files. By default, webpack listens to events triggered by the filesystem, but VirtualBox has many problems with this.” see https://webpack.js.org/guides/development-vagrant/ the webpack guide is about vagrant with virtualbox. but this option work for the wsl2-problem too.
I moved my repos to WSL path and all working fine \wsl$\Ubuntu-20.04\home\Username\test
I solved my problem when I moved the project into linux directory!
I’ll close this issue out, as it’s contingent on the feature ask to add file watching to the Plan9 server which we are tracking here: https://github.com/microsoft/WSL/issues/4064. I’ll also take it as an action item to add a quick note to the WSL2 docs about the UX change between WSL 1 and WSL 2 on this.
If you’re experiencing this issue please place your files in the Linux root file system and run from there, if you are still experiencing this issue after that then please feel free to comment here or reopen. Thank you! 😃
After increasing the max_user_watches, HRM still not working. I need to refresh the page manually
@way-zer although this looks like it might work
I think I may try this tonight and I will report back here.
Thanks!
I encountered this issue when editing files which are located in the mounted folders /mnt/c/… regardless from where I edit the files (wls or windows). It does not detect the file change.
When working in /home or local folder if I edit the file it works.
I’m afraid this is a known limitation of file-mounts and is not fixable.
I tried to repro this again using this sample calculator React project but was unable to do so. It was able to reload live without any issues.
If you’re experiencing this issue please make sure that you are running inside of your Linux root file system. If you still find that your page is not auto updating then please post a sample solution that we can try and repro the problem on, thank you!
Only @chloesun shared the solution that worked for me… so I am going to write it more straightforward:
Try adding a
.envwithCHOKIDAR_USEPOLLING=trueon it, this fixed it for me, because I am not storing the files insideWSLbut in a different disk on Windows (/mnt/d/)…Ok thank you! @craigloewen-msft I can see now that the idea is separating the operating systems completely. If I am using the vscode following the steps here =>https://code.visualstudio.com/blogs/2019/09/03/wsl2
I am able to edit and reloading works. I think the key item I did not understand is that I am not able to really use my files in /mnt in the same way.
I don’t know if that was totally clear that was the case. Anyways I moved everything into /var/www and it all started working again. Thanks everyone for the help!
@way-zer I don’t think its a port issue more so webpack-dev-server does not seem to be watching the files when I make a change the frontend does not rebuild. But the initial build works I can see it on port 3000. Its the rebuilding that does not happen but those hacks are pretty awesome.
That’s a workaround only. It’s falling back to polling instead of using native file system events, causing 80% constant CPU usage.
Experienced the same issue, and this works for me. just change your start script in the
package.jsonto{ ... "start": "CHOKIDAR_USEPOLLING=true react-scripts start" ... }The Create-React-App HRM troubleshooting documentation needs to be updated to cover the problem with the current state of WSL 2. I spent hours across a week trying to figure out what was wrong based on the current React documentations to finally discover just now that it is an issue that isn’t mentioned in the react repos. It was a problem with WSL2 app / WIN10 filesystem integration all along.
2023 and I hate to necro this, but WSL2 on windows 11 is currently unable to HMR with Sveltekit. Any possibility of a long term fix on this?
none of these options work for me, I always see people suggesting moving the repo to the wsl path, but even projects made from scratch in my linux home dont work. Love wsl2 but man this sucks
Yes we have this documentation page: UX Changes between WSL 1 and WSL 2 with the exact goal of documenting these changes. I’ll add in a note there about the fact that inotify events (which power live reloading) are not tracked in WSL 2 in your Windows drive file system. 😃
Enable-WindowsOptionalFeature -Online -FeatureName VirtualMachinePlatformEnable-WindowsOptionalFeature -Online -FeatureName:Microsoft-Hyper-V -Allwsl --set-version <DistroName> 2wsl --set-version <DistroName> 1I am also experiencing this issue +1
same here https://github.com/withastro/astro/issues/2728
Upon further digging through issues I found the following two open issues that are related, I’ll be looking at them more thoroughly later when I get time but thought I’ll link them here incase others get to this issue regarding HRM not working on WSL2.
#4739 [WSL2] File changes made by Windows apps on Windows filesystem don’t trigger notifications for Linux apps #4064 File contents differs on mounted Windows drive between Windows and WSL
@dzegarra Thank you! The Remote Development extension worked perfectly! I hope other people see this thread and see this solution!
@craigloewen-msft so If I run anything inside of /mnt/ it wont work ? thanks!
@craigloewen-msft thanks for the sample, tested it out and worked perfectly which left me stumped for a couple days. Turns out the problem was with the version of the module bundler I was using, which had a recently documented bug I’d never encountered so after I tried my usual tricks with the bundler I jumped to conclusions about it being WSL, my apologies!
Really excited this is working as expected and that I ended up being at fault, this is a really cool project!
What if I want an instant backup of it ? (disregard GIT or any other VCS). I use other hard drive and through
/mntI use that hard drive… This should be seamlessly and it is not…This has other issues. Syncing and indexing will be very slow of intellij products.
Using polling is not a solution, just a workaround as I previously mentioned. Without WSL Docker already solves this by forwarding native events (it was dixed not so long ago after years of waiting). The same should be done here.
@nake89 manually from the bash terminal or using VSCode with the Remote Development extension. The 2nd option is my preferred.
We’ve labelled your issue as ‘need-repro’ since we need more steps to help identify your problem. Could you please provide us with reproducible steps for the issue you’re experiencing, including things such as the specific command line steps necessary to reproduce the behavior and their output. Thank you! -The WSL Team
@Biswa96
vue, but I belive that any HRM framework can reproduce this errornpm run serveand wait the server upnetwork ipworks.