shadow-cljs

https://github.com/thheller/shadow-cljs | https://github.com/sponsors/thheller | https://www.patreon.com/thheller
Shako Farhad 2021-04-21T10:28:17.361800Z

Anyone here using shadow-cljs in an ubuntu 20.04 environment under WSL2 on WIndows 10? After upgrading from WSL1 to WSL2, shadow-cljs doesn't recognize diffs in my files so it doesn't recompile. Basically hot reloading doesn't work. Force compile from the server doesn't generate new files either. Anyone know what to do to fix this?

thheller 2021-04-21T10:33:53.362300Z

stick with wsl1. thats a known problem on the wsl2 side, nothing shadow-cljs can do about that

thheller 2021-04-21T10:35:46.362500Z

https://github.com/microsoft/WSL/issues/4739

thheller 2021-04-21T10:38:59.364100Z

wsl1 actually is better anyways if you work on the files from the windows side anyways. network also becomes quite annoying since the wsl2 container gets its own IP and stuff. IMHO WSL1 is still better and I use that still.

Shako Farhad 2021-04-21T10:43:41.365500Z

I had to upgrade to WSL2 because nginx didn't work properly in WSL1. And unfortunatly I need this to work since we want dev and prod environments to be as similar as possible. I will try to move my projects to the linux filesystem and see if that maybe helps.

thheller 2021-04-21T10:45:31.366Z

pretty sure that doesn't help but let me know if it does

Aron 2021-04-21T10:52:54.366300Z

I use shadow-cljs in wsl2 ubuntu

Aron 2021-04-21T10:53:16.366600Z

At least I thought that's what I am doing.

Aron 2021-04-21T10:54:17.367400Z

But yeah, I do everything from inside the wsl, even the editor runs from there (using X, kitty, nvim or alternatively vscode with their very good wsl support)

Shako Farhad 2021-04-21T11:21:38.371Z

@thheller I fixed the issue. Changes to the file now does trigger recompile. 1. I git cloned all my repositories to /home/user/src in the linux filesystem. 2. I mapped the linux filesystem network folder to a normal drive foler. Follow this short guide: https://support.microsoft.com/en-us/windows/map-a-network-drive-in-windows-10-29ce55d1-34e3-a7e2-4801-131475f9557d 3. Then I opened my repository folder with Intellij (also works with VS Code). 4. Make changes in intellij to the file -> shadow-cljs compiles and nginx serves the new file. Probably works without nginx too.

Shako Farhad 2021-04-21T11:23:06.371700Z

BTW. The compilation time seems to be faster too now. But this is just a feeling I have now, no hard data behidn that statement. 😛

thheller 2021-04-21T12:02:29.373200Z

thanks for the info

Shako Farhad 2021-04-21T12:07:03.375300Z

@thheller I notice that shadow-cljs fails to connect to the websocket when the server is serving the files over 127.0.0.1 instead of localhost. Is it possible to perhaps have the reconnection logic try both? I know it is possible to specify the host in the config file, so it is a minor issue. I just think it might lead to a bit of confusion for some?

thheller 2021-04-21T12:08:12.376400Z

thats not something that is fixable I think. I mean if you connect to 127.0.0.1 that would need to map to the container ip

thheller 2021-04-21T12:08:32.376800Z

dunno how that is handled for localhost, maybe thats another adapter or has some forwarding logic

thheller 2021-04-21T12:08:53.377200Z

by default the browser websocket connect logic will use the host you used to open the page

Aron 2021-04-21T12:11:02.379500Z

if you do nginx, you have to forward the ports imho

Aron 2021-04-21T12:11:57.380Z

and the reason it works with localhost I think is some OS level magic related to WSL

Aron 2021-04-21T12:12:25.380500Z

tell me if I am wrong 🙂

Shako Farhad 2021-04-21T12:13:16.381100Z

Ah really?

server {
    listen 127.0.0.1:80;
    include /home/dev/src/locations.conf;
}
THis is what I have in my nginx config.

thheller 2021-04-21T12:13:51.381800Z

but do you have something extra on the windows side?

thheller 2021-04-21T12:14:08.382400Z

last time I checked it didn't automagically forward ports but it has been a while

thheller 2021-04-21T12:14:25.382900Z

otherwise the 9630 port should also just work

Aron 2021-04-21T12:16:02.384800Z

I checked and I have nothing about the 9630 anywhere and it works

Shako Farhad 2021-04-21T12:16:04.384900Z

Nothing special on the windows side. The locations is just:

location /client/ {
    alias /home/dev/src/client/resources/public/;
}
So going to 127.0.0.1/client/ will load up everything. Shadow-cljs is stuck reconnecting and then stops trying. Changing it to localhost makes shadow-cljs connect right away and everythign works. :x

Aron 2021-04-21T12:16:08.385100Z

the ws server and webui

Aron 2021-04-21T12:17:28.386300Z

but obviously not with 127.0.0.1

thheller 2021-04-21T12:18:02.387200Z

neat, guess I should test that again. dealing with network ports was very annoying last time I tried

Shako Farhad 2021-04-21T12:19:31.388100Z

Yeah

:http {:port 9630
       :host "127.0.0.1"}
this does not help. Looks like the server is not started at http://127.0.0.1:9630/, at least my browser shows nothing when trying to open that page. So even when specifying the host, the reconnection fails.

Aron 2021-04-21T12:19:46.388300Z

Aron 2021-04-21T12:20:29.389Z

do you absolutely need the 127.0.0.1?

Shako Farhad 2021-04-21T12:20:32.389200Z

NAME            STATE           VERSION
* Ubuntu-20.04    Running         2

Shako Farhad 2021-04-21T12:20:58.389800Z

Hehe I don't think so. I will check things on my side.

Aron 2021-04-21T12:26:24.392700Z

have you tried searching for shadow-cljs in the WSL github issues?

Shako Farhad 2021-04-21T12:26:45.393Z

No, I haven't 😮

Aron 2021-04-21T12:28:15.393300Z

because this had some TIL for me https://github.com/microsoft/WSL/issues/4851

Aron 2021-04-21T12:29:44.394Z

a quote, because sometimes I am surprised that a vague memory turns out to be resonant > Tag needs-investigation in the sense this needs a ruling on whether the current (circa 19640) behavior of the magic WSL localhost tunnel is by-design (by fiat), or should route ipv4 `127.0.0.1` to ipv6 `::1` automatically like it does on Linux.

thheller 2021-04-21T12:30:55.394600Z

shadow-cljs defaults to binding to whatever address is returned by localhost

thheller 2021-04-21T12:32:07.394900Z

oh wait no, it defaults to 0.0.0.0

thheller 2021-04-21T12:32:29.395200Z

but you can control this via the :http :host

Aron 2021-04-21T12:33:39.395700Z

I haven't changed anything like this. I set a dev-http and an nrepl port

lilactown 2021-04-21T17:04:47.396800Z

I upgraded to 2.12.5 and get the following when running a watch:

[2021-04-21 10:03:22.948 - WARNING] :shadow.cljs.devtools.server/nrepl-ex
Note: The following stack trace applies to the reader or compiler, your code was not executed.
CompilerException Syntax error compiling at (clojure/tools/reader/edn.clj:75:9). #:clojure.error{:phase :compile-syntax-check, :line 75, :column 9, :source "clojure/tools/reader/edn.clj"}
	clojure.lang.Compiler.analyze (Compiler.java:6808)
	clojure.lang.Compiler.analyze (Compiler.java:6745)
	clojure.lang.Compiler$InvokeExpr.parse (Compiler.java:3820)
	clojure.lang.Compiler.analyzeSeq (Compiler.java:7109)
	clojure.lang.Compiler.analyze (Compiler.java:6789)
	clojure.lang.Compiler.analyze (Compiler.java:6745)
	clojure.lang.Compiler$IfExpr$Parser.parse (Compiler.java:2837)
	clojure.lang.Compiler.analyzeSeq (Compiler.java:7107)
	clojure.lang.Compiler.analyze (Compiler.java:6789)
	clojure.lang.Compiler.analyze (Compiler.java:6745)
	clojure.lang.Compiler$BodyExpr$Parser.parse (Compiler.java:6120)
	clojure.lang.Compiler$LetExpr$Parser.parse (Compiler.java:6436)
Caused by:
RuntimeException No such var: err/throw-no-dispatch
	clojure.lang.Util.runtimeException (Util.java:221)
	clojure.lang.Compiler.resolveIn (Compiler.java:7388)
	clojure.lang.Compiler.resolve (Compiler.java:7358)
	clojure.lang.Compiler.analyzeSymbol (Compiler.java:7319)
	clojure.lang.Compiler.analyze (Compiler.java:6768)
	clojure.lang.Compiler.analyze (Compiler.java:6745)

thheller 2021-04-21T17:06:18.397200Z

wrong tools.reader version

lilactown 2021-04-21T17:06:35.397400Z

lein deps :tree shows that shadow-cljs depends on org.clojure/tools.reader "1.1.3.1"

lilactown 2021-04-21T17:06:43.397700Z

and AFAICT that's the only version present

lilactown 2021-04-21T17:08:26.398400Z

looking at the source on github, throw-no-dispatch exists

lilactown 2021-04-21T17:10:28.399100Z

if nothing else shows up on the deps tree depending on it, how do I know what's pulling in the wrong tools.reader version?

thheller 2021-04-21T17:11:52.399500Z

do you use profiles? did you active those that would be activated when starting shadow-cljs?

thheller 2021-04-21T17:12:17.400300Z

try lein repl (with profiles if needed) and (<http://clojure.java.io/resource|clojure.java.io/resource> "clojure/tools/reader/edn.clj")

lilactown 2021-04-21T17:13:55.401300Z

I don't use any profiles

lilactown 2021-04-21T17:14:45.401600Z

user=&gt; (<http://clojure.java.io/resource|clojure.java.io/resource> "clojure/tools/reader/edn.clj")
#object[java.net.URL 0x440076b6 "jar:file:/Users/lilactown/.m2/repository/org/clojure/tools.reader/1.1.3.1/tools.reader-1.1.3.1.jar!/clojure/tools/reader/edn.clj"]

thheller 2021-04-21T17:15:22.401900Z

thats the wrong version? https://clojars.org/thheller/shadow-cljs

thheller 2021-04-21T17:15:31.402300Z

org.clojure/tools.reader 1.3.3

thheller 2021-04-21T17:16:28.402700Z

where did you get the impression that shadow-cljs uses 1.1.3.1?

lilactown 2021-04-21T17:18:19.403500Z

lein deps :tree shows the following output:

[thheller/shadow-cljs "2.12.5" :exclusions [[fipp] [edn-query-language/eql] [com.wsscode/pathom]]]
   [cider/piggieback "0.5.0" :exclusions [[org.clojure/clojure] [org.clojure/clojurescript] [nrepl]]]
     [javax.xml.bind/jaxb-api "2.3.1"]
       [javax.activation/javax.activation-api "1.2.0"]
   [com.bhauman/cljs-test-display "0.1.1"]
   [com.google.javascript/closure-compiler-unshaded "v20210302"]
   [expound "0.8.5"]
   [hiccup "1.0.5"]
   [org.clojure/clojure "1.10.1"]
     [org.clojure/core.specs.alpha "0.2.44"]
     [org.clojure/spec.alpha "0.2.176"]
   [org.clojure/clojurescript "1.10.844" :exclusions [[com.google.javascript/closure-compiler-unshaded] [org.clojure/google-closure-library] [org.clojure/google-closure-library-third-party]]]
   [org.clojure/core.async "0.3.465"]
     [org.clojure/tools.analyzer.jvm "0.7.2"]
       [org.clojure/core.memoize "0.5.9"]
       [org.clojure/tools.analyzer "0.6.9"]
       [org.ow2.asm/asm-all "4.2"]
   [org.clojure/data.json "1.0.0"]
   [org.clojure/google-closure-library-third-party "0.0-20201211-3e6c510d"]
   [org.clojure/google-closure-library "0.0-20201211-3e6c510d"]
   [org.clojure/tools.cli "1.0.194"]
   [org.clojure/tools.reader "1.1.3.1"]

lilactown 2021-04-21T17:18:37.403900Z

I would expect tools.reader to appear elsewhere in the tree as well if something else depended on it?

thheller 2021-04-21T17:19:02.404300Z

odd

thheller 2021-04-21T17:19:54.404800Z

do you have it in managed-dependencies or so?

thheller 2021-04-21T17:20:23.405100Z

core.async is also the very wrong version?

lilactown 2021-04-21T17:20:44.405300Z

😐 yes

lilactown 2021-04-21T17:21:43.406Z

I'm in a monorepo that uses lein-monolith, and both tools.reader and core.async are in managed-dependencies in the root project.clj 🤦

lilactown 2021-04-21T17:21:54.406300Z

I didn't even know about managed-dependencies

lilactown 2021-04-21T17:22:04.406600Z

thanks for the help

papachan 2021-04-21T18:31:36.409100Z

I am trying to compile a serverless project with shadows-cljs which it was working until i add mongodb library from node. it seems the compilation process skip some dependency requiered by mongodb import. Someone have fall down into this before?

thheller 2021-04-21T18:32:10.409300Z

not enough info to comment. what is the actual problem?

papachan 2021-04-21T18:36:08.409500Z

When i bundle the serverless app, look like mongodb library require some extra dependency to be inmported correctly i added theses manually to the package.json but when i run the project the bundle js dont found thoses

papachan 2021-04-21T18:37:38.409700Z

i have this when i compile:

:js-options {
:js-provider :shadow
:keep-native-requires true
}

thheller 2021-04-21T18:37:58.409900Z

it would help if you tell me the actual error ...

thheller 2021-04-21T18:38:20.410100Z

mongodb might have native code dependencies

thheller 2021-04-21T18:38:47.410300Z

:js-provider :shadow is NOT recommend for node builds

thheller 2021-04-21T18:39:04.410500Z

generally https://github.com/vercel/ncc is safer, maybe that works for you

👀 1
papachan 2021-04-21T18:42:43.410900Z

@thheller i just had to create again the stacktrace: 'Module not provided: mongodb-extjson'

thheller 2021-04-21T18:45:15.411100Z

ok, that might be dynamically required (which shadow-cljs doens't detect or bundle) or it might be a native dependency

papachan 2021-04-21T18:57:51.411300Z

probably i can build the js bundle and look where it required or call it

papachan 2021-04-21T22:03:13.411600Z

@thheller is there any other idea, maybe downgrade mongodb?

papachan 2021-04-21T22:06:04.412300Z

instead of :shadow maybe :external ?

thheller 2021-04-21T22:07:55.412500Z

use the default :js-provider :require and use ncc I linked

thheller 2021-04-21T22:08:10.412700Z

external only applies for browser builds not node stuff

papachan 2021-04-21T22:30:36.412900Z

OK i am trying with ncc but should i provide a js file with the specific requires?

papachan 2021-04-21T23:09:18.413100Z

OK i get the index file

papachan 2021-04-21T23:09:57.413300Z

But how i can use it with require? i add it to my bundle dir?

papachan 2021-04-21T23:22:14.413500Z

seems to work

nivekuil 2021-04-21T23:55:16.413700Z

can shadow hot-reload css files that are @imported from the top-level css file, which is the only one explicitly included in the html?