Fork me on GitHub
#cider
<
2021-08-19
>
drewverlee19: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.

dpsutton19:08:21

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

drewverlee19: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)

dpsutton19:08:02

don't choose node

dpsutton19:08:09

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

dpsutton19:08:33

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)))

drewverlee19:08:15

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

drewverlee19: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 {....

dpsutton19:08:30

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

👍 3
dpsutton19:08:32

but not sure

drewverlee19:08:41

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

dpsutton19:08:08

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

drewverlee19: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.

dpsutton20:08:53

do you set one in your init?

drewverlee20: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> 
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

thheller20:08:19

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

thheller20:08:25

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

drewverlee20:08:11

as in, i can't cider connect?

dpsutton20:08:32

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

thheller20:08:33

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

thheller20:08:56

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

thheller20:08:51

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

thheller20:08:33

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

dpsutton20:08:42

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

dpsutton20:08:24

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

drewverlee20:08:11

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

thheller20:08:23

: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?

dpsutton20:08:38

good point 🙂

thheller20:08:12

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

thheller20:08:59

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?

thheller20:08:47

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

drewverlee20:08:08

the build id is :backend.

thheller20:08:20

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

thheller20:08:03

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)

thheller20:08:55

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

thheller20:08:10

you can still load your code in that of course

thheller20:08:40

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

drewverlee20: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.

thheller20:08:50

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).

drewverlee20:08:01

ok there is a shadow/node-repl command.

thheller20:08:02

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)

dpsutton20:08:10

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))

dpsutton20:08:27

then its just nrepl connection to shadow's nrepl server

thheller20:08:31

so there is no node-repl support?

dpsutton20:08:51

there is. let me go find exactly what it does

thheller20:08:12

(shadow/node-repl) I'd assume

dpsutton20:08:00

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

dpsutton20:08:31

so exactly as above just with the watch omitted

thheller20:08:14

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

dpsutton20:08:50

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

dpsutton20:08:16

;;  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))

dpsutton20:08:27

so you were correct

dpsutton20:08:45

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

thheller20:08:29

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

dpsutton20:08:06

oh it is? i knew you had a superior mechanism

thheller20:08:49

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

dpsutton20:08:36

sorry about that 😕 thanks for being so patient

drewverlee20:08:58

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

dpsutton20:08:27

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

drewverlee20:08:48

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

dpsutton20:08:01

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

dpsutton20:08:14

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

drewverlee20: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 🙂

thheller20:08:56

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

dpsutton20:08:42

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.

dpsutton20:08:17

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

drewverlee21: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.

dpsutton21:08:38

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