Stuck with connecting to the repl of Krell + react native + nvim + conjure

Hi all,

I’ve been practicing my Clojure skills by writing a simple react native app. Just a simple thing with two views, a notification and a bit of navigation, to get the feel for it.

So far I’ve not invested the energy in connecting to a repl from my favourite editor, and instead relied on typing in some commands in the repl to experiment before writing the final version of the code in the .cljs file. However, recently I tried connecting to a repl from Conjure, and I just cannot get it to work. This is frustrating me a lot, because emotionally I don’t want to go back to typing in the repl. Does someone know where I should look for the problem?

This is what I used to do (and what works)

Basically the steps from the readme

  1. clj -M -m krell.main -co build.edn -c -r
    after a couple of seconds this shows ‘waiting for device connection on port 5001’, and then:
  2. npx react-native start
  3. npx react-native run-android
    Leads to a succesful running of the app with a connected interactive repl (command line).

Help

(See below for the two things I’ve tried to get to work. But first my question, for comfort of the reader.)

Does someone have either

  1. Some steps to produce a working setup for (n)vim + clojurescript + react-native?
  2. Some indication of what might be wrong, or where I should be looking? Is it the device connection that I should debug (even though it is working from clj -M -m krell.main -co build.edn -c -r), or should I be looking at the way Conjure connects to the clj repl?

Re point 1: I’m also fine with other build systems, or other (n)vim plugins. As long as I can continue focussing on my little app from the comforts of a vim environment :slight_smile:

Attempt 1 (didn’t work)

  1. start a repl using clj -M:cider-krell
    with in my deps.edn:
     :cider-krell {:extra-deps {org.clojure/clojure {:mvn/version "1.10.3"}
                                cider/cider-nrepl {:mvn/version "0.26.0"}
                                cider/piggieback {:mvn/version "0.5.2"}
                               io.vouch/krell  {:git/url  "https://github.com/vouch-opensource/krell.git"
                                                :sha  "08f2bfea96aa48feb8511851e37f5948453986e5"}
                               io.vouch/reagent-react-native  {:git/url  "https://github.com/vouch-opensource/reagent-react-native.git"
                                         :sha  "0fe1c600c9b81180f76b94ef6004c2f85e7d4aa0"}
  1. open nvim + conjure, connect to this repl, and send the code from the wiki:
(require '[clojure.edn :as edn] 
         '[clojure.java.io :as io]
         '[cider.piggieback] 
         '[krell.api :as krell]
         '[krell.repl])

(def config (edn/read-string (slurp (io/file "build.edn"))))
(apply cider.piggieback/cljs-repl (krell.repl/repl-env) (mapcat identity config))
  1. Now I see the output

    and this ‘waiting for device to connection on port 5001’ is the same as what I’m getting in my working setup. But, now running npx react-native start and npx react-native run-android does not yield a repl I can send more commands to, there will be simply no response:

Attempt 2

Basically the instructions from the calva help page at: Krell - Calva User Guide
I have the feeling that a couple of days ago this did in fact work for me (attempt 1 never worked at all). But now I can’t reproduce it anymore (even after a restart of the system). Now it yields the same behaviour as at attempt 1

Thanks in advance for any help!
Florian

I don’t know what changed, but somehow my attempt number 1 is working now :smiley:

Really strange, because I spent a lot of time trying to get this to work, so I’d estimate the chance that I’ve actually tried something that I had not tried before (without noticing) as quite low.

Anyway, I can continue on my journey, so I’m 100% happy :slight_smile:

1 Like

Thanks for your detailed writing of the problem and you attempted solutions. And for letting us know you got past your road block. :blush:

I do not have any experience with Clojurescript in combination with React Native, so I wasn’t able to help, but having a written record of problems and their solution is valuable.

1 Like

@mdiin, Thanks for replying! Makes my effort feel not wasted.

As a side-note: it’s impressive to see how big a change a good repl connection from the text editor is in development efficiency but also fun. I basically have 1 day/week reserved for playing around with clojure/clojurescript. The past two days I had spent were mostly spent in frustration. But now with the working setup, way more of the problems that I run into, I perceive as fun/interesting. Just because looking up the definition, or comparing with code in the libraries I use, or just experimenting a bit becomes so much easier and quicker.

2 Likes

Can you post your source? I’m trying to get the same running but struggling haha

I’ve uploaded it here: GitHub - fvkluck/shiny-meme
Disclaimer: I wasnt planning on putting it public, so not 100% sure that I’ve got all the right folders.
This is probably the part that is most relevant for this problem.

My nvim config is mostly just: GitHub - rafaeldelboni/nvim-fennel-lsp-conjure-as-clojure-ide: Basic config to transform your NVIM in a powerful Clojure IDE using fennel, clojure-lsp and conjure.

In my ~/.clojure/deps.edn, I have:

    :aliases
...
     :cider-krell {:extra-deps {org.clojure/clojure {:mvn/version "1.10.3"}
                                cider/cider-nrepl {:mvn/version "0.26.0"}
                                cider/piggieback {:mvn/version "0.5.2"}
                               io.vouch/krell  {:git/url  "https://github.com/vouch-opensource/krell.git"
                                                :sha  "08f2bfea96aa48feb8511851e37f5948453986e5"}
                               io.vouch/reagent-react-native  {:git/url  "https://github.com/vouch-opensource/reagent-react-native.git"
                                         :sha  "0fe1c600c9b81180f76b94ef6004c2f85e7d4aa0"}
                                }
                   :main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}

And then from the command line I basically start: clj -M:cider-nrepl and in a separate pane open nvim, and then send the commands in the comment block of line 13 to the nrepl.

Let me know if you run into something, I might have encountered the same error

I’m back to the situation of my starting post again…no clue what changed. As far as I know I didnt touch the project since it last worked.

This is just so frustrating. It feels like my experience with clojure just keeps being 1 step forward, 0.9 steps back. When everything is working it feels heavenly, but it feels like I only spend 25% of my time in that state.
And I can’t even explain to myself where the 75% of time went :frowning:

Anyway, I guess I’ll abandon this project for now, and find myself a webapp toy project to build. Perhaps in a couple of weeks/months I’ll feel motivated again to either dig in deeper still, or to try an alternative setup.

Of course, no disrespect meant towards either Clojure or Krell. I’m pretty sure both are great projects, I’m just experiencing some personal frustration now :slight_smile:

I’ve never done react-native development with Clojure, but Krell is relatively new, and it is also relatively simple. That means maybe it still has some rough edges, and maybe it is meant for people who understand deeply both the Clojurescript bootstrapping and that of react native.

I can’t speak personally, but in general, it seems less people struggle with shadow-cljs GitHub - thheller/shadow-cljs: ClojureScript compilation made easy then they do with using Clojurescript compiler defaults for Clojurescript with figwheel. Maybe it be the same for you?

Next time you could try shadow-cljs (or even re-natal), and see if those work better for you.

Firstly, I’d like to echo @mdiin’s thanks for taking the time to write out your experience and findings. It helped me get past the same roadblock, with a similar setup to yours (including the same base nvim config :nerd_face:).

When I run the REPL[*], npx react-native start and npx react-native run-android in that order (as they appear in the Reagent tutorial), I get the following error in the npx react-native start log:

Could not evaluate form: (cljs.core._STAR_print_namespace_maps_STAR_ = true) [ReferenceError: Can't find variable: cljs]

If I close the REPL and re-launch it, Metro (react-native start) automatically connects to the new REPL and reloads the project. Hot reloading works, and I see the following in my Conjure log:

; eval (current-form): (apply cider.piggieback/cljs-repl (krell.repl/repl-env) (mapcat identity config))
; (out) 
; (out) Waiting for device connection on port 5001
; (out) To quit, type: :cljs/quit
nil

The error doesn’t appear if I start the REPL after Metro has bundled the app.

Hope this helps. If it doesn’t, you’re welcome to hit me up on Clojurians Slack so we can try and figure it out.


[*] To run the REPL, I added a :piggieback alias to my deps.edn, so it looks like this:

{:deps {io.vouch/krell {:git/url "https://github.com/vouch-opensource/krell.git"
                        :sha "08f2bfea96aa48feb8511851e37f5948453986e5"}
        io.vouch/reagent-react-native {:git/url "https://github.com/vouch-opensource/reagent-react-native.git"
                                       :sha "0fe1c600c9b81180f76b94ef6004c2f85e7d4aa0"}
        reagent/reagent {:mvn/version "0.10.0"
                         :exclusions [cljsjs/react cljsjs/react-dom]}}

 :aliases
 {:piggieback {:extra-deps {cider/piggieback {:mvn/version "0.5.3"}}}}}

Start an nREPL in Neovim with the vim-jack-in plugin [**]:

:Clj -A:piggieback

Connect Conjure to the REPL:

:ConjureConnect

(or <LocalLeader>cf)

And lastly, execute the piggieback code in the REPL, as you’ve documented.


[**] If you don’t want to bother with vim-jack-in, you can update the :aliases in your deps.edn as below, and run the REPL in a terminal with clj -M:piggieback.

{;...
 :aliases
 {:piggieback {:extra-deps {cider/cider-nrepl {:mvn/version "0.28.3"}
                            cider/piggieback {:mvn/version "0.5.3"}}
               :main-opts ["-m" "nrepl.cmdline" "--middleware" "[cider.nrepl/cider-middleware]"]}}

Thanks for posting this! It seems to be working again, and I’m very happy about it :slight_smile:

I won’t mark anything as an answer yet, because (at least at my local setup) it still feels like I need a little bit of voodoo rituals to get everything in working condition. I didn’t get the error

Could not evaluate form: (cljs.core._STAR_print_namespace_maps_STAR_ = true) [ReferenceError: Can't find variable: cljs]

but still it only worked correctly after restarting the REPL after metro has been started.

Let’s hope that in the future we can either completely explain the cause of the issue, and/or pinpoint more accurately what component is causing it. Last week it felt to me as though the main process worked correctly, but that the REPL just “didn’t get the memo” that all was fine and hence kept waiting for the connection. But I currently lack the experience (and motivation) to dig deeper into that. Perhaps in a couple of weeks/months I’ll revisit the problem.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.