lydell/elm-watch

Running 'example-minimal' in devcontainer wsl2 - not picking up changes to *.elm

Closed this issue · 2 comments

  1. Install vs code extension: devcontainer
  2. Run in devcontainer
  3. Make change to src/Main.elm
  4. Observe as nothing happens
  5. Do help :D
    elmish-dev-004-elm-watch-example.zip
lydell commented

Hi! Thanks for the report. I don’t doubt this is a bug, but I just wanted to let you know that I probably won’t debug this because it’s too far from any environment I use.

If you would like to debug this, a tip is that I use the chokidar library for file watching. So you could make a small Node.js script that uses chokidar and see how it picks up changes in devcontainer wsl2. Maybe there’s some option to chokidar that helps in that case, or an issue in the chokidar repo about it.

It's actually not a bug as such. It's a missing config when using devcontainers :)
Chactgpt:
File system events not propagated: By default, Docker containers do not propagate file system events from the host to the container. This can prevent Chokidar from detecting file changes. To enable file system event propagation, you can try adding the --polling flag when starting your container. For example:

bash
Copy code
docker run --name my-container --volume $(pwd):/app --workdir /app --env CHOKIDAR_USEPOLLING=true my-image
Setting the CHOKIDAR_USEPOLLING environment variable to true instructs Chokidar to use polling-based file watching, which should work even if file system events are not propagated.

The solution is to add an environment var to your devcontainer.json { "name": "Elm (Community)", "dockerFile": "Dockerfile", "containerEnv": { "CHOKIDAR_USEPOLLING": "true" },