figwheel-main icon indicating copy to clipboard operation
figwheel-main copied to clipboard

DOC figwheel-main with nREPL

Open sbondaryev opened this issue 6 years ago • 13 comments

It would be great to have a chapter which explains nREPL. And how to start figwheel-main in ClojureScript nREPL (using Leiningen and CLI Tools)

sbondaryev avatar Jul 22 '18 17:07 sbondaryev

CIDER's documentation seems to comment on this -- which should be helpful if you're using Emacs. Steps I took:

  1. M-x cider-jack-in-cljs
  2. Choose figwheel-main as type of REPL
  3. Choose :dev as build name, or something else if your build is named differently.

teodorlu avatar Sep 20 '18 15:09 teodorlu

What if I want to connect to the repl? Now I am starting figwheel with

lein run -m figwheel.main -b dev -r

but when I try to cider-connect-cljs 127.0.0.1:9500 with repl type figwheel-main, I get following messages:

[nREPL] Establishing direct connection to 127.0.0.1:9500 ...
[nREPL] Direct connection to 127.0.0.1:9500 established
nrepl-send-sync-request: Sync nREPL request timed out (op clone id 1)

Reason I am trying to connect instead of jack-in is because I get following error during jack-in:

user> RuntimeException Invalid token: :  clojure.lang.Util.runtimeException (Util.java:221)
RuntimeException Unmatched delimiter: )  clojure.lang.Util.runtimeException (Util.java:221)
RuntimeException Unmatched delimiter: )  clojure.lang.Util.runtimeException (Util.java:221)

jack-in works on different project though (tested with nodejs - current app is browser one).

nenadalm avatar Sep 21 '18 19:09 nenadalm

@nenadalm IIRC that error appears when not providing a buildname.

eval avatar Sep 22 '18 16:09 eval

@eval thank you very much. That was the reason. I usually don't read stuff programs ask me too much and it asked me to provide build name (e.g. dev). So I somehow saw the dev in the sentence and thought that it was the default (on the project with node, the build name is server-dev so I had to provide it).

nenadalm avatar Sep 22 '18 18:09 nenadalm

@nenadalm @eval I was hit by the exact same thing. I had the same assessment of the prompt: thought it was the default that it had read from my config, hit enter, saw lisp reader error.

ckampfe avatar Sep 23 '18 18:09 ckampfe

Same mistake here. Ideally, it should either default to :dev or validate and force to specify a valid value.

rinconjc avatar Nov 13 '18 19:11 rinconjc

Is it correct that you were able to connect to localhost:9500 and speak to the ClojureScript application via the nREPL protocol?

ghost avatar Nov 19 '18 18:11 ghost

What I would like to see working without much hassle is a setup like this:

  • Start Figwheel somewhere
  • Open a browser session for that Figwheel instance
  • Connect Cursive to the browser session's ClojureScript REPL
    • Preferrably via Unrepl / Socket REPL

I would prefer if I did not have to deal with much of the details of how that works / is set up -- the more that works automatic, the better.

devurandom avatar Nov 20 '18 08:11 devurandom

I tried starting Remote Repl in Cursive, switching it to CLJS, then running (figwheel.main.api/cljs-repl "dev")

i get the following output

Connecting to remote nREPL server...
Clojure 1.10.1
(figwheel.main.api/cljs-repl "dev")
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
Execution error (ExceptionInfo) at figwheel.main/nrepl-repl (main.cljc:1525).
Failed to launch Figwheel CLJS REPL: nREPL connection found but unable to load piggieback.
This is commonly caused by
 A) not providing piggieback as a dependency and/or
 B) not adding piggieback middleware into your nrepl middleware chain.
Please see the documentation for piggieback here https://github.com/clojure-emacs/piggieback#installation

Note: Cider will inject this config into your project.clj.
This can cause confusion when your are not using Cider.

I do have piggieback dependency in my "dev" profile in project.clj and :repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}

@bhauman do i understand correctly that when i run lein build-dev does not use the dev profile?

antonmos avatar Jul 12 '19 15:07 antonmos

You can add with-profiles dev to the :alias I think.

Sent from ProtonMail Mobile

On Fri, Jul 12, 2019 at 11:33 AM, Anton Mostovoy [email protected] wrote:

I tried starting Remote Repl in Cursive, switching it to CLJS, then running (figwheel.main.api/cljs-repl "dev")

i get the following output

Connecting to remote nREPL server... Clojure 1.10.1 (figwheel.main.api/cljs-repl "dev") 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 Execution error (ExceptionInfo) at figwheel.main/nrepl-repl (main.cljc:1525). Failed to launch Figwheel CLJS REPL: nREPL connection found but unable to load piggieback. This is commonly caused by A) not providing piggieback as a dependency and/or B) not adding piggieback middleware into your nrepl middleware chain. Please see the documentation for piggieback here https://github.com/clojure-emacs/piggieback#installation

Note: Cider will inject this config into your project.clj. This can cause confusion when your are not using Cider.

I do have piggieback dependency in my "dev" profile in project.clj and :repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}

@bhauman do i understand correctly that when i run lein build-dev does not use the dev profile?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.

bhauman avatar Jul 12 '19 17:07 bhauman

changed the alias to :aliases {"build-dev" ["with-profile" "dev" "trampoline" "run" "-m" "figwheel.main" "-b" "dev" "-r"]} but it didnt help.

updating piggiback to 0.4.1 didnt help either.

Anything else i can try?

antonmos avatar Jul 12 '19 20:07 antonmos

Is it correct that you were able to connect to localhost:9500 and speak to the ClojureScript application via the nREPL protocol?

Yes, I got this working, although it doesn't seem to be documented clearly right now. Here is what worked for me:

  • piggieback middleware
  • from an nREPL connection:
(def fwth (doto (Thread. #(figwheel.main/start :dev)) .start)) ;; separate thread, it blocks
(figwheel.main.api/cljs-repl "dev") ;; must be a string, not a keyword

The following silently returns nil and doesn't appear to work (starting again as above complains that A build with id "dev" is already running. {})

(figwheel.main/stop-builds :dev)

But I do now have CLJS+CIDER with figwheel-main and a single jvm process for both clojure and cljs, so I'm a happy person.

blak3mill3r avatar Apr 07 '20 01:04 blak3mill3r

I tried starting Remote Repl in Cursive, switching it to CLJS, then running (figwheel.main.api/cljs-repl "dev")

i get the following output

Connecting to remote nREPL server...
Clojure 1.10.1
(figwheel.main.api/cljs-repl "dev")
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
Execution error (ExceptionInfo) at figwheel.main/nrepl-repl (main.cljc:1525).
Failed to launch Figwheel CLJS REPL: nREPL connection found but unable to load piggieback.
This is commonly caused by
 A) not providing piggieback as a dependency and/or
 B) not adding piggieback middleware into your nrepl middleware chain.
Please see the documentation for piggieback here https://github.com/clojure-emacs/piggieback#installation

Note: Cider will inject this config into your project.clj.
This can cause confusion when your are not using Cider.

I do have piggieback dependency in my "dev" profile in project.clj and :repl-options {:nrepl-middleware [cider.piggieback/wrap-cljs-repl]}

@bhauman do i understand correctly that when i run lein build-dev does not use the dev profile?

Turned out, my app was starting another nREPL server using luminus-nrepl, which does not honor repl-options in project.clj, so it was not including the piggieback middleware.

In my case the solution is roughly:

  • configure piggieback per https://github.com/nrepl/piggieback#leiningen
  • dont use lein run -m figwheel.main -b dev -r to start the app (because leiningen will not start nREPL in this case)
  • use lein repl
  • connect remote repl to nrepl port .nrepl-port file (generated by leiningen)
  • run (do (require '[figwheel.main.api :as fig]) (fig/start "dev")))

antonmos avatar Dec 01 '20 22:12 antonmos