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

Sensei does not recompile on change on WSL2 #117

Closed
zigarn opened this issue Nov 8, 2021 · 12 comments · Fixed by #180
Closed

Sensei does not recompile on change on WSL2 #117

zigarn opened this issue Nov 8, 2021 · 12 comments · Fixed by #180

Comments

@zigarn
Copy link
Contributor

zigarn commented Nov 8, 2021

https://stackoverflow.com/questions/62780245/nodemon-and-webpack-dev-server-hot-reload-not-working-under-wsl-2-after-windows/62790703#62790703

A solution would be to support --watch-poll

@zigarn
Copy link
Contributor Author

zigarn commented Jan 18, 2022

Ping @moreau-nicolas: still relevant? Maybe fixed by #132?

@hgwood
Copy link
Member

hgwood commented Jan 18, 2022

No, as far as I can tell, because I experience this issue too and it's different.

In #131, webpack was recompiling but the browser did not refresh. Here, webpack does not recompile.

@hgwood hgwood changed the title No hot reload on docker in WSL2 Sensei does not recompile on change on WSL2 Jan 18, 2022
@hgwood
Copy link
Member

hgwood commented Jan 18, 2022

I should add that this issue is relevant when:

  • sensei is run inside a Docker container
  • the Docker back-end is WSL2
  • the training material folder is a Windows folder (as opposed to a Linux folder)

@zigarn
Copy link
Contributor Author

zigarn commented Jan 18, 2022

So it would be that webpack or docker volume doesn't detect FS changes on Windows FS, not sure we could do anything on that, may be a solution would be simply document this use case and propose a workaround (using Unix FS)?

@hgwood
Copy link
Member

hgwood commented Jan 18, 2022

The stackoverflow page you linked suggests that the training folder should be moved to the Linux FS or that sensei should support polling like you said. I need to test the polling possibility.

@hgwood
Copy link
Member

hgwood commented Jan 18, 2022

Here's how Next does it: vercel/next.js#302

hgwood added a commit that referenced this issue Jan 19, 2022
See #117. Setting SENSEI_WATCH_POLL to 'true' now makes webpack poll to watch source files, making it possible to live reload on WSL2. Could be useful in other situations also.
@hgwood
Copy link
Member

hgwood commented Jan 19, 2022

I've found a fix and committed it to the watch_poll branch. It's stacked on top of #136 so waiting on #136 to merge before opening a PR.

@moreau-nicolas
Copy link
Contributor

moreau-nicolas commented Feb 7, 2022

On sensei latest version I do not have the problem : Webpack recompiles, and the browser refreshes. I'm using VS Code with the WSL extension, running sensei from a WSL2 prompt, and launching Code from WSL2 too.

It seems it works better if Code is started after webpack (from another console tab).

@hgwood
Copy link
Member

hgwood commented Feb 7, 2022

Interesting. Is the working directory part of the Windows FS or the WSL FS? Also, was sensei installed from Windows or from WSL?

@moreau-nicolas
Copy link
Contributor

The working directory is within the Windows FS, accessed through WSL via Ubuntu bash (/mnt/c/Users/Nicolas/...).
Sensei is a bash alias within WSL2.
Hope this helps.
We can arrange a call if needed.

@zigarn
Copy link
Contributor Author

zigarn commented Dec 22, 2022

I tested multiple combinations with WSL2 (not WSL1, may differ in term of FS handling from what I found):

Docker or native Filesystem Environment Command Result
Docker Windows Windows docker container run --pull always --interactive --tty --rm --volume //c/Users/alex/training-template:/training-template --workdir //training-template --publish 8080:8080 --env SENSEI_PORT --cap-add=SYS_ADMIN zenika/sensei No reload
Docker Windows WSL docker container run --pull always --interactive --tty --rm --volume //mnt/c/Users/alex/training-template:/training-template --workdir //training-template --publish 8080:8080 --env SENSEI_PORT --cap-add=SYS_ADMIN zenika/sensei No reload
Docker WSL WSL docker container run --pull always --interactive --tty --rm --volume /home/alex/training-template:/training-template --workdir /training-template --publish 8080:8080 --env SENSEI_PORT --cap-add=SYS_ADMIN zenika/sensei Reload
Native Windows Windows sensei serve C:/Users/alex/training-template Reload
Native Windows WSL sensei serve /mnt/c/Users/alex/training-template Watchpack Error (initial scan): Error: EACCESS: permission denied, lstat '/mnt/c/pagefile.sys'
Native WSL WSL sensei serve /home/alex/training-template Reload
Native WSL (network device) Windows sensei serve //wsl.localhost/Ubuntu/home/alex/training-template CMD.EXE was started with the above path as the current directory. UNC paths are not supported. Defaulting to Window directory.
Then errors because not in right folder so no slides.json
Native WSL (drive) Windows net use U: //wsl.localhost/Ubuntu; sensei serve U:/home/alex/training-template fatal: detected dubious ownership in repository at '//wsl.localhost/Ubuntu/home/alex/training-template'
Native WSL (drive, git safe) Windows net use U: //wsl.localhost/Ubuntu ; git config --global --add safe.directory '*' ; sensei serve U:/home/alex/training-template Errors about handling "c:" URIs, and paths in "C:Usersalex" (without \ nor /)

Tested 344959c (need rebase) and it does solve the problem if we don't forgot to set SENSEI_WATCH_POLL=true.

But Docker WSL2 best practices state that best option is to have the code in WSL FS, mount it directly in docker container and access it through \\wsl$ on Windows side.
Maybe the best option for sensei is to simply update the README.md to advise this solution? WDYT @hgwood @moreau-nicolas?

@hgwood
Copy link
Member

hgwood commented Jan 3, 2023

Yes I think it's a good idea. We can still add SENSEI_WATCH_POLL later and change the readme to reflect.

hgwood added a commit that referenced this issue Jan 26, 2023
See #117. Setting SENSEI_WATCH_POLL to 'true' now makes webpack poll to watch source files, making it possible to live reload on WSL2. Could be useful in other situations also.
hgwood added a commit that referenced this issue May 22, 2023
This can help get hot reloading work when running sensei with a VM-backed Docker from a host file system folder. For example, when running sensei with Docker for Windows with the WSL2 back-end from a Windows file system folder (see #117) or when running sensei with Colima from a macOS file system folder (see lima-vm/lima#615). The recommendation still is to work off the VM file system to get native file watching.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants