Fork me on GitHub
Drew Verlee19:08:05

How would i get a Nrepl to a shadow-cljs build that's targeting a node-library:

{:exports-var blah
                    :target :node-library
                    :output-dir "out/backend/"
                    :output-to "out/backend/main.js"}
I tried connecting via cider-connect-cljs shadow-cljs and node, both said the connected by neither let me eval ed the code.


shadow always starts an nrepl server right? It should just be there. just cider-jack-in and select the build you care about and it should just work

Drew Verlee19:08:39

there is a project script that starts the shadow and the repl i can connect to. I was able to use cider-connect-cljs for the frontend part but not the backend. I tried the node and shadow connection option. The node one throws an execution error:

;; ClojureScript REPL type: node
;; ClojureScript REPL init form: (do (require 'cljs.repl.node) (cider.piggieback/cljs-repl (cljs.repl.node/repl-env)))
Execution error (AssertionError) at shadow.cljs.devtools.server.nrepl/shadow-cljs-repl (nrepl.clj:30).
Assert failed: (keyword? repl-env)


don't choose node


choose shadow-cljs. and then choose the build name you care aobut


the node option starts a cljs.main repl who's repl env is cljs.repl.node > (do (require 'cljs.repl.node) (cider.piggieback/cljs-repl (cljs.repl.node/repl-env)))

Drew Verlee19:08:15

thanks. Also, in case it's part of the issue. What is the difference between "shadow" and "shadow-select"?

Drew Verlee19:08:22

trying to connect with with repl type: shadow gives me a no build id: app. Which is confusing because neither my /.shadow-cljs/config.edn or my project-cljs.edn mentions a build with id app.

1. Unhandled clojure.lang.ExceptionInfo
   no build with id: :app
   {:tag :shadow.cljs.devtools.config/no-build, :id :app}
                config.clj:  156  shadow.cljs.devtools.config/get-build!
                config.clj:  154  shadow.cljs.devtools.config/get-build!
the only mention of an app is the modules key e.g :modules {:app {....


i think shadow-select is the "connect" version of connecting to a running shadow instance

👍 3

but not sure

Drew Verlee19:08:41

hmm maybe a dir-locals configuration is getting picked up.


yeah clear those out. absolutely should be given a list of choices. and it parses your shadow-cljs.edn file to list the available builds

Drew Verlee19:08:42

Yea. that must be it, as your right, it wasn't giving me a choice of build. I'm perplexed because there isn't a dir-locals file in the project.


do you set one in your init?

Drew Verlee20:08:56

i'm not sure what you mean. This is the information i'm reading on my end:

;; ClojureScript REPL type: shadow
;; ClojureScript REPL init form: (do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/watch :app) (shadow/nrepl-select :app))
Execution error (ExceptionInfo) at shadow.cljs.devtools.config/get-build! (config.clj:156).
no build with id: :app
[:frontend] Configuring build.
[:frontend] Compiling ...
[:frontend] Build completed. (229 files, 0 compiled, 0 warnings, 1.14s)
shadow.user> (do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/watch :backend) (shadow/nrepl-select :backend))
To quit, type: :cljs/quit
[:selected :backend]No available JS runtime.
See  available JS runtime.
The no js runetime error makes sense to me backend targets a node-library


no build with id: :app. the build id appears to be :frontend or :backend?


if you want to REPL into :backend you need to actually start it yourself. meaning the actual node process.

Drew Verlee20:08:11

as in, i can't cider connect?


node the-file-i-said-to-output.js


can't comment on any cider related things but I think no. you still connect to shadow-cljs as normal


but you backend needs to be started and then that one will also connect to shadow-cljs which will then let you talk to that one in the REPL


if you don't actually need any of this use the built-in node-repl. don't know how you do that for cider but that one manages the node process for you


can't explain it any better than I attempted in the docs 😛


cider allows you to choose that build. it looks at all of the builds in the shadow-cljs.edn and also includes browser and node repls


and i believe what @thheller is saying is that if you use the node-repl included repl, shadow will start the node process for you. If you are using :npm-lib, shadow will compile your stuff into a js file (`:output-to` i think) and then you need to manually run node that-file.js and then your repl will have its runtime. The same way you need to load your webapp before you can use the frontend repl

Drew Verlee20:08:11

ah, makes sense. something called nodemon is calling the outputed js file.


:node-library outputs are not meant to be called directly by anything? they are meant to be imported by something else? hence the "library" name?


good point 🙂


:node-script is for actual "application" type things


but again: if you just want a node REPL use node-repl, not :backend. you can still start your backend from there just fine, but you don't have to manage your node process?


but I don't know what you are doing so backend might be the correct one

Drew Verlee20:08:08

the build id is :backend.


think of node-repl being the same as clj or lein repl


where as the REPL for :node-script or :node-library is a REPL embedded in your-actual-program, like starting your own nrepl server or something (not really, just for comparison sake)


node-repl is not tied and does not care about a build id. it is standalone and generic, just like clj or lein repl


you can still load your code in that of course


really need to find a better way to explain this ... it really isn't all that complicated 😛

Drew Verlee20:08:59

one point of confusion is your talking about node-repl like thats a script/program i should be aware of. As where i thought what we were saying is that i was going to run node somefile.js and then tell my nrepl server to connect to it with a node protocol.


again .. I don't have the slightest clue what cider/emacs looks like these days. I'm talking about it in terms of shadow-cljs and what the docs there talk about (hopefully).

Drew Verlee20:08:01

ok there is a shadow/node-repl command.


as in shadow-cljs node-repl or shadow-cljs cljs-repl backend (I would assume there is a comparable option for those in emacs but don't know)


and the only thing that CIDER ever does is this command, parameterized over the build name (do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/watch :app) (shadow/nrepl-select :app))


then its just nrepl connection to shadow's nrepl server


so there is no node-repl support?


there is. let me go find exactly what it does


(shadow/node-repl) I'd assume


i think it's actually (shadow/nrepl-select :browser-repl) or :node-repl


so exactly as above just with the watch omitted


that can't work? needs to be started first?


i actually haven't started up CIDER in a while now. let me go see exactly what it does


;;  Startup: /usr/local/bin/npx shadow-cljs -d nrepl/nrepl:0.8.3 -d cider/piggieback:0.5.2 -d cider/cider-nrepl:0.25.9 server
;; ClojureScript REPL type: shadow
;; ClojureScript REPL init form: (do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/node-repl))


so you were correct


and CIDER still isn't smart enough to not add piggieback when using shadow


doesn't matter these days and is actually required (not used still, just got tired of trying to "fake" it)


oh it is? i knew you had a superior mechanism


faking it was just too problematic, now its just added as normal but the shadow-cljs middleware places itself before piggieback. so that never actually does anything but is still there to make cider happy and stuff


sorry about that 😕 thanks for being so patient

Drew Verlee20:08:58

@dpsutton what did you run to get it to run shadow/node-repl?


cider-jack-in-clojurescript then choose shadow then choose node-repl

Drew Verlee20:08:48

i must have some global configuration somewhere that's setting things. ugh.


yes. that's what i said before about you probably setting it in your init


but no matter. it seems like you can just call (shadow/node-repl) yourself when it throws an error with trying to do :app

Drew Verlee20:08:17

That seems to work. thanks a lot. Will shadow watch/recompile a node target like it does a browser one? I realize were in the cider channel 🙂


yes, although reloading is often a bit trickier. depends on how much state you keep in those nasty node callbacks and such 😉


i added the server startup commands and the cljs repl startup commands at the top of the repl so you'd see you just get a regular clj repl and then use shadow's api commands to "upgrade" the repl into a cljs repl.


there's no magic. it's just getting a clojure repl and running (do (require '[shadow.cljs.devtools.api :as shadow]) (shadow/node-repl)) that's just clojure code

Drew Verlee21:08:12

The offending configuration problem was coming form my spacemacs/emacs-custom-settings in my init file. I don't recall it every causing this type of issue before. i just removed it as it's auto generated.


if you've always wanted the :app build in the past i'm sure it was a conveinience