Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WSL2: nodemon file watcher no longer working #4169

Closed
adamlacombe opened this issue Jun 17, 2019 · 19 comments
Closed

WSL2: nodemon file watcher no longer working #4169

adamlacombe opened this issue Jun 17, 2019 · 19 comments

Comments

@adamlacombe
Copy link

adamlacombe commented Jun 17, 2019

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.

@therealkenc
Copy link
Collaborator

therealkenc commented Jun 17, 2019

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.

@therealkenc therealkenc added the wsl2 Issue/feature applies to WSL 2 label Jun 17, 2019
@adamlacombe
Copy link
Author

adamlacombe commented Jun 17, 2019

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

@canselcik
Copy link

canselcik commented Jun 24, 2019

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

@therealkenc
Copy link
Collaborator

therealkenc commented Oct 10, 2019

#4064 #4739 as LZ

@LiamKarlMitchell
Copy link

LiamKarlMitchell commented Apr 14, 2020

@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?

@onomatopellan
Copy link

onomatopellan commented Apr 14, 2020

@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/

@rodrigogs
Copy link

rodrigogs commented May 16, 2020

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

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

@Yassine-49
Copy link

Yassine-49 commented May 31, 2020

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

@Witti
Copy link

Witti commented May 31, 2020

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$

@fonziemedia
Copy link

fonziemedia commented Jul 2, 2020

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

@LiamKarlMitchell
Copy link

LiamKarlMitchell commented Jul 3, 2020

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

@fonziemedia
Copy link

fonziemedia commented Jul 3, 2020

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

@mohemos
Copy link

mohemos commented Sep 2, 2020

@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?

@fonziemedia
Copy link

fonziemedia commented Sep 5, 2020

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

@LiamKarlMitchell
Copy link

LiamKarlMitchell commented Sep 5, 2020

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.

@therealkenc therealkenc added duplicate and removed wsl2 Issue/feature applies to WSL 2 labels Sep 6, 2020
@areizas
Copy link

areizas commented Feb 7, 2021

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.

@nuran571
Copy link

nuran571 commented Feb 7, 2021

@nuran571
Copy link

nuran571 commented Feb 7, 2021

@slim-hmidi
Copy link

slim-hmidi commented Mar 3, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests