shadow-cljs

Gosha 2025-01-27T10:43:15.022779Z

Hi! I have a question about tooling, and specifically starting the REPL. I work with Emacs and Cider, and before I added CLJS to my project I was starting a regular (I assume) Clojure REPL via the Cider jack-in command. Now, I followed the full-stack workflow post from Thomas Heller (https://code.thheller.com/blog/shadow-cljs/2024/10/18/fullstack-cljs-workflow-with-shadow-cljs.html), and that got me starting a separate shadow-cljs REPL in a terminal, and then connecting to it from Emacs. I’m a beginner at Clojure, so I’m not sure about the differences between the two. I assume it’s not problematic to just use the Clojure REPL started via shadow-cljs? Is there a way to make it so that this REPL is the one started via Cider jack in? Or is there another approach that’s a best practice? Grateful for any insights! 🙏

Gosha 2025-02-02T21:58:59.585989Z

I ended up running the REPL from the command line with clj -M -m shadow.cljs.devtools.cli clj-repl and connecting to it from CIDER. Then I switch to the cljs repl with (shadow.cljs.devtools.api/repl :frontend) as needed. Happy with this workflow!

Gosha 2025-01-27T10:43:36.608419Z

I should also say that I tried to just load the shadow-cljs API namespace into the normal Clojure REPL that starts via jacking in in Cider, but this forced me to add a dependency to my deps.edn (`commons-codec/commons-codec`), which makes me feel like I might run into some other missing dependencies down the line.

thheller 2025-01-27T12:32:12.418969Z

jack in is pretty much the same as starting the REPL via shadow-cljs. the only thing that may be different is how dependencies are declared/used. if you follow the described setup they should all be in deps.edn, so dunno why anything would be missing.

thheller 2025-01-27T12:32:31.426199Z

jack in is nothing else than cider starting the JVM process for you and then connecting the REPL

thheller 2025-01-27T12:32:47.570749Z

instead of you starting the JVM process manually (via shadow-cljs) and then connecting

Gosha 2025-01-27T15:56:57.827969Z

@thheller Thank you! That makes sense. I was able to trace this behaviour in the shadow-cljs code, too: when you run clj -M -m shadow.cljs.devtools.cli clj-repl, it ends up executing clojure.main/repl in the end.

thheller 2025-01-27T18:08:49.607239Z

thats not the REPL used when your editor connects, but yeah close enough

Ken Huang 2025-01-28T01:41:03.277379Z

There is also a jack in command for cljs: M-x cider-jack-in-cljs.

Ken Huang 2025-01-28T01:44:01.270409Z

And in theory, you can M-x cider-jack-in-clj&cljs to start two REPLs in one go, but it's tricky to get it work for my project somehow. So I just start them by running M-x cider-jack-in-clj and M-x cider-jack-in-cljs separately.

mauricio.szabo 2025-01-27T17:01:26.568129Z

Hi folks! So... a question: I don't suppose there's a workaround for the limitation of being unable to run multiple ClojureScript projects in the same runtime, in watch mode, right? The context is: I'm making editor plug-ins with ClojureScript. Unfortunately, this means if I am developing two different plug-ins at the same time (`shadow-cljs watch`, basically) they conflict with each other because of the Closure compiler, some globals that get defined, etc. I decided to check the ESM target to see if I could bypass this, but it doesn't seem so (it just gives me a Namespace "cljs.core" already declared.). So I'm just checking here if someone was able to do some... magic, maybe with some external tools... to circumvent this.

Ken Huang 2025-01-28T01:46:17.480099Z

shadow-cljs can watch multi targets at the same time, have you tried that?

mauricio.szabo 2025-01-28T03:14:59.135749Z

These are different projects, so that won't work for me...

mauricio.szabo 2025-01-28T03:15:48.834529Z

Although I think I found a VERY HACKY way. I'll test it better and check if it works

witek 2025-01-27T19:00:10.279329Z

I would like to test http://automerge.org. But I get this error:

Failed to inspect file
  /p/localmo.de/node_modules/@automerge/automerge-repo/dist/index.js

Errors encountered while trying to parse file
  /p/localmo.de/node_modules/@automerge/automerge-repo/dist/index.js
  {:line 35, :column 9, :message "'from' expected"}
Any ideas what is causing the error?

witek 2025-01-27T19:14:10.361839Z

Thank you, @macroz I have added the following into my shadowcljs.edn:

:js-options {:js-provider :external
                     :external-index "public/js/external-index.js"}
But now I get:
hook.js:608 Failed to load shadow.js.shim.module$react.js ReferenceError: shadow$bridge is not defined
    at eval (shadow.js.shim.module$react.js:3:41)
    at eval (<anonymous>)
    at goog.globalEval (main.js:456:11)
The shadow-cljs documentation mentions I need to use webpack or something. I have never used webpack or anything like that. Can you point me to an example of a shadow-cljs project with :js-provider :external ?

witek 2025-01-27T19:17:21.158349Z

Or could / should I use Automerge from a CDN instead?

Macroz 2025-01-27T19:27:20.624389Z

There are some older threads with that error also. Sorry that I don't have a direct answer 🤷

witek 2025-01-27T19:39:39.776859Z

No problem, I will try Yjs instead.

manas_marthi 2025-01-27T20:28:22.230149Z

Does anyone have a sample project that uses ExpressJS and its middlewares and EJS templates with the appcode in Clojurescript?