Fork me on GitHub
#cider
<
2021-12-01
>
quoll02:12:05

I’ve finally decided that I can’t rely on a console repl for ClojureScript on node anymore, and I’m trying to use Cider, since that’s what I use with Clojure. Unfortunately, I haven’t been able to make it work. I’ve added cider/piggieback to my deps.edn, and added the recommended alias:

:aliases {:cider-cljs {:main-opts ["-m" "nrepl.cmdline" "--middleware"
                                   "[cider.nrepl/cider-middleware,cider.piggieback/wrap-cljs-repl]"]}}
Then when I use M-xcider-jack-in-cljs I give my desired repl as node This responds with a banner, and finishes with:
;;  Startup: /usr/local/bin/clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.8.3"} cider/piggieback {:mvn/version "0.5.2"} cider/cider-nrepl {:mvn/version "0.26.0"}} :aliases {:cider/nrepl {:main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware,cider.piggieback/wrap-cljs-repl]"]}}}' -M:cider/nrepl
;;
;; ClojureScript REPL type: node
;; ClojureScript REPL init form: (do (require 'cljs.repl.node) (cider.piggieback/cljs-repl (cljs.repl.node/repl-env)))
;;
user>
So I type: (+ 2 3) to see if it works, and I get:
TypeError: Cannot read property 'error__GT_str' of undefined
    at Socket.<anonymous> ([stdin]:89:28)
    at Socket.emit (events.js:400:28)
    at Socket.emit (domain.js:470:12)
    at addChunk (internal/streams/readable.js:290:12)
    at readableAddChunk (internal/streams/readable.js:261:11)
    at Socket.Readable.push (internal/streams/readable.js:204:10)
    at TCP.onStreamRead (internal/stream_base_commons.js:188:23)
    at TCP.callbackTrampoline (internal/async_hooks.js:131:17)
So now I’m stuck. Any advice is welcome please.

Drew Verlee02:12:50

do you have to run the init form it suggets? (do (require 'cljs.repl.node) (cider.piggieback/cljs-repl (cljs.repl.node/repl-env)))

quoll02:12:35

well, I’ve since discovered that I don’t have to type anything and I get that stack trace after a few seconds

quoll02:12:51

given that (+2 3) doesn’t work, then I don’t think that form will do anything

quoll02:12:26

I just tried anyway, because I really don’t know what I’m doing… but no, nothing happens.

Derek02:12:52

Are you activating your :cider-cljs alias?

quoll02:12:08

I don’t understand that question, sorry

Derek02:12:43

The startup command:

Startup: /usr/local/bin/clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.8.3"} cider/piggieback {:mvn/version "0.5.2"} cider/cider-nrepl {:mvn/version "0.26.0"}} :aliases {:cider/nrepl {:main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware,cider.piggieback/wrap-cljs-repl]"]}}}' -M:cider/nrepl
doesn’t seem to have the :cider-cljs alias within it

Drew Verlee02:12:48

when you run cider-jack-in-cljs it won't run with the :cider-cljs alias you setup unless you add it to your dir locals file

Derek02:12:14

You can manually insert it by C-u M-x cider-jack-in-cljs

Derek02:12:16

and inserting it

Derek02:12:22

or .dir-locals

Derek02:12:55

I believe I set cider-clojure-cli-global-options in the .dir-locals file

Derek02:12:11

But I think the prefix argument (C-u) would be a good first try

Drew Verlee02:12:11

in your project root you would add the file ".dir-locals.el"

((clojurescript-mode
  (cider-clojure-cli-aliases . "-A:cider-cljs")
  )))
docs: https://docs.cider.mx/cider/config/project_config.html

Derek02:12:24

oh even better

Drew Verlee02:12:32

I think, i manage to always F it up though 😢

Drew Verlee02:12:11

FWIW, i don't know if that will fix things. I always start clojure script through shadow

quoll02:12:10

OK, I’ve tried this, but to no avail

Derek02:12:24

Did you see the alias in the startup command?

Derek02:12:38

-M:cider-cljs:cider/nrepl is what we’re hoping to see

quoll02:12:02

;;  Startup: /usr/local/bin/clojure -Sdeps '{:deps {nrepl/nrepl {:mvn/version "0.8.3"} cider/piggieback {:mvn/version "0.5.2"} cider/cider-nrepl {:mvn/version "0.26.0"}} :aliases {:cider/nrepl {:main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware,cider.piggieback/wrap-cljs-repl]"]}}}' -M:cider-cljs:cider/nrepl
;;
;; ClojureScript REPL type: node
;; ClojureScript REPL init form: (do (require 'cljs.repl.node) (cider.piggieback/cljs-repl (cljs.repl.node/repl-env)))

quoll02:12:40

looks like the command was updated, but not the aliases. I don’t know how they get updated?

quoll02:12:59

evidently not my deps.edn :)

Derek02:12:02

I wouldn’t expect to see your project alias in the aliases map

Derek02:12:09

those are the injected ones from CIDER

Derek02:12:15

that command, to my eyes, looks correct

Derek02:12:00

I think, unfortunately, we’ve solved a problem, not the problem

quoll02:12:47

Maybe I just need to learn how to use shadow

Drew Verlee02:12:50

[stands up on a desk] My name is drew verlee. i have been doing cljs development for like 3 years on and off, i have no idea how to get a cljs repl running correctly without shadow or figwheel.

Drew Verlee02:12:58

i await someone to be along shortly and show me a one line of code to do it.

quoll02:12:36

I started setting up shadow on a test project earlier, but hadn’t actually done anything with it. I just tried it now. Worked perfectly

quoll02:12:48

So… apparently shadow is what I’m using from now on

quoll03:12:08

Nope… spoke too soon. I have a working repl, that’s true, but I can’t load namespaces

thheller09:12:53

maybe to clarify how things work in shadow-cljs. shadow-cljs itself is written in Clojure so the default REPL you start out with is CLJ. From there you can control shadow-cljs itself, all via CLJ. One thing you can do is select/switch your CLJ REPL to a CLJS REPL. either that is coupled to a build or not

thheller09:12:25

from the command line for example you can do shadow-cljs clj-repl which connects you do the CLJ REPL. in there you can run (shadow/node-repl) which will switch that REPL to CLJS running in node

thheller09:12:53

or (shadow/browser-repl) or (shadow/repl :your-build-id)

thheller09:12:44

that is basically what you need cider to do. Can't tell you how but I believe you got it to work in the end

thheller09:12:03

so the "can't load namepaces" likely means you are still in a CLJ REPL that needs to be switched

thheller09:12:42

all the other CLI commands also basically directly translate to REPL commands

thheller09:12:58

shadow-cljs clj-repl (shadow/watch :my-build) same as shadow-cljs watch my-build only that you still have a open REPL connection to do more (eg. start another build, stop it, etc)

quoll11:12:05

It was my mistake… I was running emacs in the wrong project. It contained identical files, so I hadn’t realized that I was in the wrong place. Very embarrassing 😳

quoll03:12:18

C-c C-k says that it’s loading the file, but then it just sits there. If I look at any symbols (it’s test file with a single defn in it) then they’re not defined

Drew Verlee22:12:30

I started by repl via cljs-jack-in-cljs selected my shadow config and the app rendered without error in my browser. I have my nrepl server buffer running telling me nrepl is on a port, and i havea repl buffer where i can type in commands. However, cider eval last sexp does nothing and if tell cider to quit it tells me "no repls in the current session"

dpsutton22:12:27

put your cursor in the cljs repl and then try again?

dpsutton22:12:35

(not a joke. i suspect this will fix it)

Drew Verlee22:12:56

it says my repl is connected. it's like it goes through all the steps but doesn't establish the connection

dpsutton22:12:54

weird. is it possible you’ve navigated to a dependency or something? It sounds like everything is working but it doesn’t recognize the source buffer as being in the project that is connected to the repl

Drew Verlee22:12:18

err, ugh. i just had a half formed thought. I know why its happening in a vague way.

Drew Verlee22:12:43

It's on my end, not emacs or cider, but how the project is setup.

dpsutton22:12:34

are the sources in another directory?

dpsutton22:12:55

there’s something like sesman link directory or equivalents that should hopefully help you correct all that

Drew Verlee22:12:37

@dpsutton i think the namespaces are excluded in the compilation step. We have feature flags. When i switched to a different ns everything worked.

dpsutton22:12:33

womp. well sounds like its for sure your end. and hopefully there is a workaround