WSL: WSL2: nodemon file watcher no longer working

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.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 21

Most upvoted comments

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

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

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.

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

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

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 😃

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