Fork me on GitHub
#shadow-cljs
<
2023-05-05
>
joshcho04:05:54

Hi all, my current project has shadow-cljs for frontend and lein for the backend. This creates problems in CIDER, where I cannot be connected to both instances. I would like to use cider-connect-clj&cljs, and it seems I need both to be the same build tool (lein or shadow-cljs). How would I accomplish this? I currently have a project.clj and shadow-cljs.edn. Do I need to change shadow-cljs.edn to use lein, or somehow convert project.clj into shadow-cljs?

thheller05:05:34

I'm pretty sure cider can connect to two instances, so you can leave everything as is. you can move dependencies from shadow-cljs.edn to project.clj to launch via lein https://shadow-cljs.github.io/docs/UsersGuide.html#Leiningen

joshcho10:05:39

It seems cider gets confused about the two instances (two different ports). I moved the dependencies like in the manual, but I am getting "Clojurescript is not available" when running cider-connect-sibling-cljs. Here is shadow-cljs.edn:

{:lein {:profile "+cljs"}
 :nrepl {:port 8777}

 :jvm-opts ["-Xmx1G"]

 :dev-http
 {8280 "resources/public"
  8290 "target/browser-test"}

 :builds
 {:app
  {:target     :browser
   :output-dir "resources/public/js/compiled"
   :asset-path "/js/compiled"
   :modules
   {:app {:init-fn re-frame-proj.core/init}}
   :devtools
   {:preloads [
               ;; devtools.preload
               ;; re-frisk.preload
               ]}
   :dev
   {:compiler-options
    {:closure-defines
     { }}}}}}
and project.clj:
(defproject re-frame-proj "0.1.0-SNAPSHOT"
  :description "Backend server for Slix using Clojure."
  :url ""
  :license {:name "EPL-2.0 OR GPL-2.0-or-later WITH Classpath-exception-2.0"
            :url ""}
  :dependencies [[org.clojure/clojure "1.11.1"]
                 [ring/ring-core "1.8.2"]
                 [ring/ring-jetty-adapter "1.8.2"]
                 [cider/cider-nrepl "0.28.4"]
                 [org.clojure/tools.namespace "1.3.0"] ; used for lispy
                 ;; [org.clojure/java.jdbc "0.7.12"]
                 ;; [org.xerial/sqlite-jdbc "3.40.1.0"]
                 [compojure "1.7.0"]
                 ;; [com.github.seancorfield/honeysql "2.4.972"]
                 [ring-cors "0.1.13"]
                 [ring/ring-json "0.5.1"]
                 [org.clojure/data.json "2.4.0"]
                 [io.aviso/pretty "1.3"]
                 ;; for memory measurement
                 [com.clojure-goes-fast/clj-memory-meter "0.2.1"]
                 ;; [datascript "1.4.0"]
                 ;; [io.replikativ/datahike "0.6.1531"]
                 [dev.weavejester/medley "1.6.0"]
                 [clj-time "0.15.2"]
                 [datalevin "0.8.5"]
                 ;; [org.clojars.quoll/asami "2.2.4"]
                 ]
  :main re-frame-proj.core
  ;; for memory measurement
  :jvm-opts ["-Djdk.attach.allowAttachSelf" "-Xmx8G"]
  :repl-options {:init-ns re-frame-proj.core}
  :profiles
  {:cljs
   {:source-paths ["src"]
    :dependencies
    [[thheller/shadow-cljs "2.23.3"]
     [reagent "1.1.1"]
     [re-frame "1.3.0"]

     [binaryage/devtools "1.0.7"]
     [re-frisk "1.6.0"]
     [cider/cider-nrepl "0.28.4"]

     [cljs-http "0.1.46"]
     [cljs-ajax "0.8.4"]
     [day8.re-frame/http-fx "0.2.4"]
     [clj-commons/secretary "1.2.4"]
     [com.cemerick/url "0.1.1"]
     [venantius/accountant "0.2.5"]
     [com.rpl/specter "1.1.4"]
     [philoskim/debux "0.8.3"]
     [expound "0.9.0"]
     [re-com "2.13.2"]]}}
  )

thheller10:05:33

sorry, can't answer cider questions. I don't have the slightest clue how it works. I'd assume the cider docs cover everything.

hifumi12310:05:30

I’ve used CIDER with Leiningen and Shadow CLJS before, but too much information is omitted in the project.clj for me to tell what is possible going wrong

hifumi12310:05:56

e.g. where is the nrepl middleware? are you using the proper version of cljs and google-closure for your version of shadow-cljs?

joshcho10:05:02

@hifumi123 I have edited the file so that it's in full. It seems I am missing some dependencies on lein side that is necessary for cljs?

thheller10:05:10

if thats using the lein nrepl server (not the shadow-cljs one) you need to add :nrepl-middleware https://shadow-cljs.github.io/docs/UsersGuide.html#_embedded_nrepl_server

hifumi12310:05:41

IIRC you also need to provide your own CLJS dependency and ensure it is compatible with shadow-cljs version youre using

thheller10:05:23

not necessarily. shadow-cljs also brings it in. only need to be explicit if you have conflicts, ie. another dependency bringing in an older incompatible version

hifumi12310:05:00

Ah, I see. For good measure I always used :managed-dependencies so that org.clojure/clojurescript was pinned to the exact version shadow-cljs would depend on.

thheller10:05:19

a good way to avoid conflicts for sure

joshcho10:05:33

I got it to work. Thanks for the help! I haven't delved into leiningen before, so I had some trouble with profiles.

👍 2
Ben Lieberman16:05:52

Is there shadow-cljs.edn config equivalent to that shown https://clojure.org/guides/deps_and_cli#socket_repl? I have shadow-cljs running in server mode on a remote host. I tried connecting with netcat but that seems to time out (though I guess I'm missing configuration I probably need).

thheller18:05:38

what is it you are trying to do exactly?

thheller18:05:51

why do you think you need a socket repl server? is nrepl not enough?

Ben Lieberman18:05:01

No nrepl works I'm just curious if there's some extra steps I need to take bc the connection is refused or else it times out. But that might be beyond the scope of anything shadow can deal with I suppose

Ben Lieberman18:05:40

I have server running but when I connect through calva and put in the IP address port combo it does not work

thheller18:05:56

by default nrepl listens only on localhost for security reasons

thheller18:05:19

are you aware how insecure it is to have an "open" repl server? is this all running in a trusted network or the open internet?

Ben Lieberman18:05:08

Not specifically but certainly sounds like a bad idea. But yeah this is private domain at work

thheller18:05:56

you have several options, I recommend keeping nrepl on localhost and using a ssh reverse tunnel

thheller18:05:19

that at least keeps it somewhat controlled on who can access it

Ben Lieberman18:05:15

Good to know. I'll check that out. Thanks for the advice.

thheller18:05:25

it is also possible to just follow the article you linked and launch shadow-cljs in that repl if you want

thheller18:05:00

but that again has all the security implications, so I would recommend the ssh tunnel for that too

gratitude 2