I’m trying to setup a CLJ(S) development environment for a full-stack hobby project on WSL2 on Windows 10.
Just wanted to report my experience. Maybe this is helpful for others and maybe someone has a few suggestions or can tell me what I did wrong.
Installing WSL2 was easy basically just wsl --install (see Install WSL | Microsoft Docs for more infos). I’m using Ubuntu as distro.
Then I created a project with a leiningen template with shadow-cljs for the frontend. Up to this point everything was relatively easy…
I started shadow-cljs watch and opened the browser. So far so good.
I first started all clojure tools in a podman container but due to the following troubles I dropped the container and just run everything directly on WSL. However, if you want to user containers you need to configure 3 ports (the app server, the shadow-cljs server and the nREPL). Since you need to specify the ports when starting the container they must be configured in the various configuration files since they will be random otherwise.
From here I ran into various issues.
Issue 1: shadow-cljs does not detect changes to the files in the Windows filesystem. I found some hints about a polling mode but could not get it to work.
This was easy to solve: move the code to the WSL filesystem.
Issue 2: Emacs on Windows is not able to write to the WSL filesystem. Found some suggestions about advising a function to ignore the underlying ACL issues. I also thing TRAMP could work around this. However, this would not help due to the next issue.
Issue 3: I cannot connect from Windows to a repl started in WSL or vice versa. (ConnectException Connection refused: connect)
This seems to be a general issue with nREPL in WSL and not a cider issue. Strangely other ports for the server and shadow-cljs works without issues.
This issue is the worst for me since it rules out using other windows tools effectively with the exception of VS Code.
With its remote development tools it is able to have the UI in native Windows and access the tools and the nREPL port in WSL. The Calva extension appears to be fairly good. However I was a bit
confused about the jack-in options. Somehow Calva provided the options "my-project Serve"r and “my-project Server + Client”. After some research I guess it magically detected how to start the server from the connected repl. Not sure how it knows which function to start (and what if the code does not have a
function to start the server?).
Know I tried to install Emacs in WSL (emacs-nox, elpa-cider). The shadow-cljs documentation explains how to start the watch repl. In the Cider repl I tried to start the server as Calva does it but got another error
Issue 4: “No available JS runtime.”
The shadow-cljs doc suggestions that you need a browser connected which is strange since I need the server to connect the browser. But the solution was easy. The steps in the shadow-cljs doc start a CLJS repl and you just need to drop “back” to a CLJ repl (:cljs/quit) then I could start the server the same as Calva does it with function provided by the luminius template.
So after some trouble I think I have all tools working in WLS (container should also work from here) and I can either user VS Code via remote development or terminal emacs inside WSL.
P.S. Can someone recommend a color scheme for terminal emacs in Windows terminal? The default blue on black in the minibuffer is barely readable.