Fork me on GitHub
#cider
<
2020-02-05
>
Joe Corneli14:02:54

Hi everyone, I am struggling to get CIDER connected to a CLJS REPL using Figwheel.

Joe Corneli14:02:18

I can get to this:

Joe Corneli14:02:31

Figwheel: Stopped watching build - admin
Figwheel: Stopping Websocket Server
Figwheel: Starting server at 
Figwheel: Watching build - admin
Compiling build :admin to "resources/public/js/admin.js" from ["src/cljs" "src/cljc" "test/cljs"]...
Successfully compiled build :admin to "resources/public/js/admin.js" in 1.408 seconds.
Launching ClojureScript REPL for build: admin
Figwheel Controls:
          (stop-autobuild)                ;; stops Figwheel autobuilder
          (start-autobuild id ...)        ;; starts autobuilder focused on optional ids
          (switch-to-build id ...)        ;; switches autobuilder to different build
          (reset-autobuild)               ;; stops, cleans, and starts autobuilder
          (reload-config)                 ;; reloads build config and resets autobuild
          (build-once id ...)             ;; builds source one time
          (clean-builds id ..)            ;; deletes compiled cljs target files
          (print-config id ...)           ;; prints out build configurations
          (fig-status)                    ;; displays current state of system
          (figwheel.client/set-autoload false)    ;; will turn autoloading off
          (figwheel.client/set-repl-pprint false) ;; will turn pretty printing off
  Switch REPL build focus:
          :cljs/quit                      ;; allows you to switch REPL to another build
    Docs: (doc function-name-here)
    Exit: :cljs/quit
 Results: Stored in vars *1, *2, *3, *e holds last exception object
Prompt will show when Figwheel connects to your application

user> 

Joe Corneli14:02:18

but the prompt is still user> which is not what I want

Joe Corneli14:02:39

If I look in the browser, I see:

Joe Corneli14:02:04

[Figwheel REPL] Session ID: 2bae1fc5-52ca-4b0c-bc34-60ec5e85ff6b console.js:203:20 [Figwheel REPL] Session Name: Brant console.js:203:20

Joe Corneli14:02:27

So, if I understand correctly Figwheel has connected to the application

Joe Corneli14:02:16

ClojureScript REPL init form: (do (use 'figwheel-sidecar.repl-api) (start-figwheel!) (cljs-repl))

Joe Corneli14:02:55

I don't see any complaints from CIDER about missing dependencies, but I don't get the desired repl.

Joe Corneli14:02:46

Is it relevant that I get the same Figwheel REPL session name when I reload the page?

dpsutton14:02:43

if you edit a file does the UI hotload the changes?

Joe Corneli16:02:17

Attempting to run this inside inf-clojure I got a somewhat more revealing error message:

Prompt will show when REPL connects to evaluation environment (i.e. a REPL hosting webpage)
Figwheel Main Controls:
          (figwheel.main/stop-builds id ...)  ;; stops Figwheel autobuilder for ids
          (figwheel.main/start-builds id ...) ;; starts autobuilder focused on ids
          (figwheel.main/reset)               ;; stops, cleans, reloads config, and starts autobuilder
          (figwheel.main/build-once id ...)   ;; builds source one time
          (figwheel.main/clean id ...)        ;; deletes compiled cljs target files
          (figwheel.main/status)              ;; displays current state of system
Figwheel REPL Controls:
          (figwheel.repl/conns)               ;; displays the current connections
          (figwheel.repl/focus session-name)  ;; choose which session name to focus on
In the cljs.user ns, controls can be called without ns ie. (conns) instead of (figwheel.repl/conns)
    Docs: (doc function-name-here)
    Exit: :cljs/quit
 Results: Stored in vars *1, *2, *3, *e holds last exception object
Syntax error (SocketException) compiling at (/tmp/form-init8063575831097884698.clj:1:73).
Permission denied

Full report at:
/tmp/clojure-8929986480762187171.edn

Process inf-clojure exited abnormally with code 1

dpsutton16:02:13

can you run this all from the command line wihtout CIDER?

Joe Corneli16:02:58

I get the same Socket Exception error as just above when running it from the command line.

dpsutton16:02:20

then CIDER can't help you. if your project doesn't work, it can't work in CIDER

Joe Corneli16:02:48

Well it maybe depends on how lein is being started... Clearly the project is working when it is run in Docker (as I said, I can connect via a web browser)

Joe Corneli16:02:36

I am running it with lein repl now and I see:

Joe Corneli16:02:52

[Figwheel] Successfully compiled build shared to "target/public/cljs-out/shared-main.js" in 25.204 seconds.
[Figwheel] Watching paths: ("src/cljs" "src/cljc" "test/cljs") to compile build - shared
[Figwheel] Starting Server at 
JavaScript environment will not launch automatically when :open-url is false
"To start a cljs repl call `(figwheel/cljs-repl \"app\")`"
"where `app` is the build you want to attach to."
nREPL server started on port 3888 on host 0.0.0.0 - 
REPL-y 0.4.3, nREPL 0.6.0
Clojure 1.10.1
OpenJDK 64-Bit Server VM 1.8.0_242-8u242-b08-0ubuntu3~18.04-b08
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

user=> 

Joe Corneli16:02:10

The socket error came when starting it with lein fig -- -bb shared -bb shopping -b admin -r. It seems to go better without the extra instructions.

dpsutton16:02:11

needs the cljs prompt that shows when the app is connected

mikerod17:02:40

Didn’t realize that wasn’t the one

Joe Corneli17:02:01

Here's an interaction log on the command line:

Joe Corneli17:02:10

$ lein repl
2020-02-05 17:19:03.291:INFO::main: Logging initialized @4551ms to org.eclipse.jetty.util.log.StdErrLog
"To start a cljs repl call `(figwheel/cljs-repl \"app\")`"
"where `app` is the build you want to attach to."
nREPL server started on port 3888 on host 0.0.0.0 - 
REPL-y 0.4.3, nREPL 0.6.0
Clojure 1.10.1
OpenJDK 64-Bit Server VM 1.8.0_242-8u242-b08-0ubuntu3~18.04-b08
    Docs: (doc function-name-here)
          (find-doc "part-of-name-here")
  Source: (source function-name-here)
 Javadoc: (javadoc java-object-or-class-here)
    Exit: Control+D or (exit) or (quit)
 Results: Stored in vars *1, *2, *3, an exception in *e

user=> (use 'figwheel-sidecar.repl-api)
(use 'figwheel-sidecar.repl-api
nil
user=> (start-figwheel!)
(start-figwheel!
Figwheel: Starting server at 
Figwheel: Watching build - admin
Figwheel: Cleaning build - admin
Compiling build :admin to "resources/public/js/admin.js" from ["src/cljs" "src/cljc" "test/cljs"]...
WARNING: cljs.core/<=, all arguments must be numbers, got [#{nil js/Number} number] instead at line 1193 resources/public/js/admin/clojure/test/check/generators.cljc
WARNING: cljs.core/<=, all arguments must be numbers, got [#{nil js/Number} number] instead at line 1193 resources/public/js/admin/clojure/test/check/generators.cljc
WARNING: Cannot resolve property getElementById for inferred type js/HTMLDocument in expression (. js/document getElementById "app") at line 14 src/cljs/com/openmarkets/exchange/ui/shopping/core.cljs
Successfully compiled build :admin to "resources/public/js/admin.js" in 34.411 seconds.
nil
user=> (cljs-repl)
(cljs-repl
Launching ClojureScript REPL for build: admin
Figwheel Controls:
          (stop-autobuild)                ;; stops Figwheel autobuilder
          (start-autobuild id ...)        ;; starts autobuilder focused on optional ids
          (switch-to-build id ...)        ;; switches autobuilder to different build
          (reset-autobuild)               ;; stops, cleans, and starts autobuilder
          (reload-config)                 ;; reloads build config and resets autobuild
          (build-once id ...)             ;; builds source one time
          (clean-builds id ..)            ;; deletes compiled cljs target files
          (print-config id ...)           ;; prints out build configurations
          (fig-status)                    ;; displays current state of system
          (figwheel.client/set-autoload false)    ;; will turn autoloading off
          (figwheel.client/set-repl-pprint false) ;; will turn pretty printing off
  Switch REPL build focus:
          :cljs/quit                      ;; allows you to switch REPL to another build
    Docs: (doc function-name-here)
    Exit: :cljs/quit
 Results: Stored in vars *1, *2, *3, *e holds last exception object
Prompt will show when Figwheel connects to your application

Joe Corneli17:02:56

When I browse to 0.0.0.0:3449 I see a white page, and I found this interesting error in the log: "ClojureScript could not load :main, did you forget to specify :asset-path?"

Joe Corneli17:02:01

So, yeah, this a CIDER issue as far as I can tell!

Joe Corneli17:02:21

I will ask in the #figwheel channel.

Joe Corneli18:02:08

OK, I have managed to connect CIDER to the app

Joe Corneli18:02:15

But I am running into another error

Joe Corneli18:02:42

The backtrace indicates that it may have to do with cider piggieback

Joe Corneli18:02:55

... Do I even need cider-piggieback?

Joe Corneli18:02:14

My sense is that I do

Joe Corneli18:02:20

I think the problem was that I was browsing to the base URL in the project, not the relevant path from whith to engage with the particular app. Now that I am past that, here are my interactions leading to the next error:

user> (require '[figwheel-sidecar.repl-api :as fs])
nil
user> (figwheel/cljs-repl "admin")
Prompt will show when REPL connects to evaluation environment (i.e. a REPL hosting webpage)
Figwheel Main Controls:
          (figwheel.main/stop-builds id ...)  ;; stops Figwheel autobuilder for ids
          (figwheel.main/start-builds id ...) ;; starts autobuilder focused on ids
          (figwheel.main/reset)               ;; stops, cleans, reloads config, and starts autobuilder
          (figwheel.main/build-once id ...)   ;; builds source one time
          (figwheel.main/clean id ...)        ;; deletes compiled cljs target files
          (figwheel.main/status)              ;; displays current state of system
Figwheel REPL Controls:
          (figwheel.repl/conns)               ;; displays the current connections
          (figwheel.repl/focus session-name)  ;; choose which session name to focus on
In the cljs.user ns, controls can be called without ns ie. (conns) instead of (figwheel.repl/conns)
    Docs: (doc function-name-here)
    Exit: :cljs/quit
 Results: Stored in vars *1, *2, *3, *e holds last exception object
Open URL 
To quit, type: :cljs/quit
nil
cljs.user> (require 'cljs.analyzer.api)
nil
cljs.user> (cljs.analyzer.api/all-ns)
And here is the error:

Joe Corneli18:02:26

Show: Project-Only All 
  Hide: Clojure Java REPL Tooling Duplicates  (12 frames hidden)

1. Unhandled clojure.lang.ExceptionInfo
   #object[Error Error: No protocol method IDeref.-deref defined for
   type null: ]
   {:type :js-eval-exception,
    :error
    {:status :exception,
     :value
     "#object[Error Error: No protocol method IDeref.-deref defined for type null: ]",
     :ua-product :firefox,
     :stacktrace
     "[email protected]://exchange-cljs.test/cljs-out/admin/cljs/core.js:309:9\[email protected]://exchange-cljs.test/cljs-out/admin/cljs/core.js:2162:17\[email protected]://exchange-cljs.test/cljs-out/admin/cljs/core.js:4927:18\[email protected]://exchange-cljs.test/cljs-out/admin/cljs/analyzer/api.js?zx=huuvsoaczikn:197:73\[email protected]://exchange-cljs.test/cljs-out/admin/cljs/analyzer/api.js?zx=huuvsoaczikn:183:33\[email protected]://exchange-cljs.test/cljs-out/admin/cljs/analyzer/api.js?zx=huuvsoaczikn:193:33\[email protected]://exchange-cljs.test/cljs-out/admin/cljs/analyzer/api.js?zx=huuvsoaczikn:179:33\[email protected]://exchange-cljs.test/cljs-out/admin/figwheel/repl.js line 751 > eval:1:94\[email protected]://exchange-cljs.test/cljs-out/admin/figwheel/repl.js line 751 > eval:9:3\[email protected]://exchange-cljs.test/cljs-out/admin/figwheel/repl.js:751:24\[email protected]://exchange-cljs.test/cljs-out/admin/figwheel/repl.js:799:56\[email protected]://exchange-cljs.test/cljs-out/admin/cljs/core.js:35676:106\[email protected]://exchange-cljs.test/cljs-out/admin/cljs/core.js:35943:20\nfigwheel.repl.ws_connect.cljs$core$IFn$_invoke$arity$variadic/</<@http://exchange-cljs.test/cljs-out/admin/figwheel/repl.js:1053:30\[email protected]://exchange-cljs.test/cljs-out/admin/goog/events/eventtarget.js:284:23\[email protected]://exchange-cljs.test/cljs-out/admin/goog/events/eventtarget.js:381:26\[email protected]://exchange-cljs.test/cljs-out/admin/goog/events/eventtarget.js:196:34\<http://ngoog.net|ngoog.net>[email protected]://exchange-cljs.test/cljs-out/admin/goog/net/websocket.js:426:8\n"},
    :form (cljs.analyzer.api/all-ns),
    :js
    "try{cljs.core.pr_str.call(null,(function (){var ret__6754__auto__ = cljs.analyzer.api.all_ns.call(null);\n(cljs.core._STAR_3 = cljs.core._STAR_2);\n\n(cljs.core._STAR_2 = cljs.core._STAR_1);\n\n(cljs.core._STAR_1 = ret__6754__auto__);\n\nreturn ret__6754__auto__;\n})());\n}catch (e184785){var e__6755__auto___184786 = e184785;\n(cljs.core._STAR_e = e__6755__auto___184786);\n\nthrow e__6755__auto___184786;\n}"}
                 repl.cljc:  578  cljs.repl$evaluate_form/invokeStatic
                 repl.cljc:  499  cljs.repl$evaluate_form/invoke
       piggieback_impl.clj:  207  cider.piggieback/eval-cljs
       piggieback_impl.clj:  206  cider.piggieback/eval-cljs
       piggieback_impl.clj:  243  cider.piggieback/do-eval/fn
                  AFn.java:  152  clojure.lang.AFn/applyToHelper
                  AFn.java:  144  clojure.lang.AFn/applyTo
                  core.clj:  665  clojure.core/apply
                  core.clj: 1973  clojure.core/with-bindings*
                  core.clj: 1973  clojure.core/with-bindings*
               RestFn.java:  425  clojure.lang.RestFn/invoke
       piggieback_impl.clj:  220  cider.piggieback/do-eval
       piggieback_impl.clj:  219  cider.piggieback/do-eval
       piggieback_impl.clj:  266  cider.piggieback/evaluate
       piggieback_impl.clj:  264  cider.piggieback/evaluate
                  Var.java:  384  clojure.lang.Var/invoke
       piggieback_impl.clj:  297  cider.piggieback/wrap-cljs-repl/fn/fn/fn
       piggieback_impl.clj:  190  cider.piggieback/enqueue/fn
                  AFn.java:   22  clojure.lang.AFn/run
               session.clj:  171  nrepl.middleware.session/session-exec/main-loop/fn
               session.clj:  170  nrepl.middleware.session/session-exec/main-loop
                  AFn.java:   22  clojure.lang.AFn/run
               Thread.java:  834  java.lang.Thread/run

Joe Corneli18:02:47

Maybe this, again, hasn't got anything to do with CIDER

Joe Corneli18:02:02

But I see all of these mentions of cider.piggieback in the trace

johanatan19:02:57

I reported this one a few weeks ago on spacemacs' github but so far it hasn't gotten any response: https://github.com/syl20bnr/spacemacs/issues/13193

EmmanuelOga20:02:03

Hey there, I have a [kinda quiet] thread going on figwheel-main but I thought here would be a good place to ask these questions too. I'm wondering what happens when you cider-jack-in-clj&cljs ? 1. I'm using figwheel-main and deps.end, I'm wondering if there's going to be just one nREPL server (the one figwheel starts) and then cider just opens up two client connections, one for clj and one for cljs. 2. Another source of confusion is that, when starting figwheel-main from command line, I don't see which port it is running on, only the HTTP server port. I think I saw a .nrepl.port file being created on the folder of the project but I don't know under which circumstances and by whom (is it figwheel or cider?) Will that be there if I start the repl from the command line? My use case: I want to write a "full stack" clojure app, I'm writing some middleware to handle the API for the cljs app. I'd like to connect to a clj REPL to interact with the code of the ring-middleware mounted by figwheel, but also be able to connect to the cljs repl in order to interact with the browser code.

EmmanuelOga04:02:48

just quickly answering my own questions: 1. I'm pretty sure the answer is yes, a single nREPL is enough for clj+cljs, the piggieback middleware handles the cljs specific evaluations 2. That file seems to be created by nrepl's cmd line utility: https://github.com/nrepl/nrepl/blob/be37e0ebd13c2d341bf6a7bcd5735da45b78f909/src/clojure/nrepl/cmdline.clj#L403 which cider uses when jacking-in.

EmmanuelOga04:02:25

I'm sure there's a way to specify a custom nREPL port too, but haven't found it so far.

EmmanuelOga04:02:02

Founds this repo that just worked when running cider-jack-in-clj&cljs https://github.com/EmmanuelOga/deps-cider-cljs-reagent/blob/master/.dir-locals.el

EmmanuelOga04:02:30

ah! btw, here's the command cider is running for that particular repo

EmmanuelOga04:02:34

clojure -A:cider -Sdeps '{:deps {nrepl {:mvn/version ""0.6.0""} cider/piggieback {:mvn/version ""0.4.2""} cider/cider-nrepl {:mvn/version ""0.23.0""}}}' -m nrepl.cmdline --middleware '[""cider.nrepl/cider-middleware"", ""cider.piggieback/wrap-cljs-repl""]'

EmmanuelOga04:02:06

...and there it is the -m nrepl.cmdline part that invokes the code that writes teh port to that file

dpsutton20:02:20

if its the interaction between clojure-mode and another package configured through spacemacs probably not much we can do in CIDER

johanatan22:02:43

@dpsutton can you take a look at the issue I reported in spacemacs? It’s definitely a bug in the clojure layer of spacemacs

dpsutton22:02:58

can you tag me on github? working now and have a haircut after work

johanatan22:02:31

What is your GitHub username?

dpsutton22:02:51

dpsutton. same as here

johanatan22:02:18

Weird. It does not autocomplete. But I did type it out manually. Hopefully it will tag you.

dpsutton22:02:50

got an email. i'll look into it 👍

johanatan22:02:49

Awesome, thank you!! 🙏

johanatan22:02:37

👍:skin-tone-2: