microsoft / WSL

Issues found on WSL

Home Page:https://docs.microsoft.com/windows/wsl

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

WSL2: nodemon file watcher no longer working

adamlacombe opened this issue · comments

Your Windows build number: 10.0.18917.1000

What you're doing and what's happening:

Distributor ID: Ubuntu
Description:    Ubuntu 18.04.2 LTS
Release:        18.04
Codename:       bionic

I'm running nodemon@1.19.1

My working directory is located in /mnt/c/Users/Adam/Documents/...

My nodemon.json:

{
  "watch": [
    "**/*.ts"
  ],
  "ext": "ts",
  "ignore": [
    "./test/*.ts",
    "./node_modules/**/node_modules"
  ],
  "exec": "node -r ts-node/register Index.ts",
  "env": {
    "NODE_ENV": "development"
  }
}

I run: nodemon --delay 1500ms --signal SIGTERM and then modify a file that is being watched.

I'm modifying the file from outside WSL, but I have also tried from within WSL using nano.

What's wrong / what should be happening instead: After updating to WSL2 nodemon no longer triggers a restart of my application.

I'm able to run nano ./modified_file.ts and see the change.

In another project built with Stencil@1.0.4 I'm able to run stencil build --dev --watch --serve and file modifications trigger a reload.

Yep. The /Build 2019 presentation the devs mention that they (quoth) "still need to plumb" inotify(7) on the 9p filesystem. The word "plumb" is carrying a lot of weight there. Ref #1956 (message).

In the meantime, the WSL 2 launch blog post suggests:

We understand that we have spent the past three years telling you to put your files into your C drive when using WSL 1, but this is not the case in WSL 2. To enjoy the faster file system access in WSL 2 these files must be inside of the Linux root file system.

Faster, yes. But for the purposes of your scenario (and a few other edge cases), also to have access to the complete set of ext4 filesystem features.

That makes sense. Moving my project into the linux file system solves the issues with inotify. Thanks

This is related to #4064 (comment) just like #4224.

@therealkenc @adamlacombe Could you please elaborate on how to solve this by putting the project into the linux file system so that inotify works?

Would like to be able to run docker containers from windows, map the files in as volumes and have changes auto-reload by using inotify/related tools e.g. nodemon/hotreload/Quasar is this possible?

@LiamKarlMitchell the linux file system is the /home/* folder. It will work faster and better if you move/clone your code there. Also remember to install any tool you need in it's Linux version.

The Docker for Windows Edge with WSL2 backend supports your scenario but you will also need to use VSCode + Remote Extensions in order to edit files with inotify support inside the Linux distro.
It was explained in https://www.docker.com/blog/developing-docker-windows-app-wsl2/

Just run wsl --set-version {my_linux} 1

Yeah, go back to WSL 1, it just works.

Just run wsl --set-version {my_linux} 1

Yeah, go back to WSL 1, it just works.

but what if you are using WSL 2 for a reason

Just run wsl --set-version {my_linux} 1
Yeah, go back to WSL 1, it just works.

but what if you are using WSL 2 for a reason

You can migrate all your projects to the linux partition within WSL and then access the files via \\wsl$

That makes sense. Moving my project into the linux file system solves the issues with inotify. Thanks

@adamlacombe do you mean you've managed to get nodemon working on WSL 2 by moving the project into the linux file system?

Does this not give you issues when editing files from a windows code editor? I can't seem edit any linux file systems files from Visual Studio Code per example..

Thanks

Yeah it works fine in the WSL 2 file system faster as well :)

Thanks @LiamKarlMitchell!
I just had to give permissions to my projects folder to enable editing from vs code and it's all working great :)

@fonziemedia how did you give the permission? Do you still have your files on windows file system or you also moved it to linux file system?

Hi @mohemos
I moved the files to the Linux file system as advised on this thread and then did the following on WSL:
sudo chown -R [username]:[group] [directory_name]
example:
sudo chown -R cartman:cartman projects

Extra info:
I'm using Remote WSL on VS code.
To check the user VS code uses I opened a remote terminal inside VS code and typed:
whoami
To check your group:
groups
This is for Ubuntu But it may vary depending on the Linux dist you're using

Hope this helps

Only issue so far with having the code in WSL is that git kraken is rather sluggish on large projects. You can run an XServer in it and launch GUI from WSL however.

I am using the WSL 2 and I solved the issue by adding the following env variable: CHOKIDAR_USEPOLLING=true

This is how looks like my nodemon command:

CHOKIDAR_USEPOLLING=true nodemon index.js

Now you can keep WSL2 instead of moving your environment to WSL1.

I face the same issue here.
wsl -l -v :

  NAME                   STATE           VERSION
* docker-desktop         Running         2
  docker-desktop-data    Running         2

Should I download any linux distribution like ubuntu to work with it on windows. When I update any file in the node server, it takes around 3 minutes for nodemon to take into consideration the changes and reload the server and it is long time. The previous version of docker took 30s to reload the server and I can access the app to see the changes.

Great! We made WSL2 but file system is working slower and file watching is broken :-)

@slim-hmidi , yeah so I run Ubuntu on WSL2 and have source files for projects etc on the WSL2 file system, it is faster than running it on the Windows side, but that means you also need tools that can work with the wsl path (intelij ide's seems to work ok other than generated files from cli not updating in IDE fast but you can rightclick reload from disk)

It does mean I have two installations of gitkraken but im actually trying to use the git that is built-in to intelij/phpstorm more frequently atm which seems to work well.

When I ran from windows and volume mapped a directory of source code or other files I watched, to do hot-reload etc it did not work great from windows filesystem side.

As mentioned, you can set nodemon to poll, but thats naff as well and doesn't work great if you have a very large project.

Alternatively using vscode worked well actually but its not my main ide.