Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

clojure - cider-connect-clj cannot connect to nrepl.server/start-server

A) I'm having a problem where Cider can't cider-connect-clj (or cider-connect-cljs) to an nREPL server I launch in my application code. Cursive also doesn't work. It must be a simple configuration or middleware that needs to be included. But I've been looking at this code too long. What I missing?

I have a Clojure file that looks something like this.

(ns some.namespace
  (:require nrepl.server
            cider.nrepl))

(nrepl.server/start-server
  :port 1234
  :handler
  (fn [_]
    (nrepl.server/default-handler cider.nrepl/cider-middleware)))

nrepl.server/start-server starts ok. From Emacs I can connect by calling cider-connect-clj (or cider-connect-cljs). But then the REPL fails to initialize on a "sync" request.

i. Emacs console

[nREPL] Direct connection to localhost:6776 established
nrepl-send-sync-request: Sync nREPL request timed out (op clone id 1 time-stamp 2021-02-04 23:13:46.789763000)

ii. nREPL console

[WARNING] No nREPL middleware descriptor in metadata of null, see nrepl.middleware/set-descriptor!

B) I'm actually running Figwheel-Main and connecting an nREPL, for a Clojurescript connection. All within my Clojure app.

;; λ clj -A:dev -m some.namespace
:dev
{:extra-paths ["dev" "test"]
 :extra-deps {org.clojure/clojure       {:mvn/version "1.10.0"}
              org.clojure/clojurescript {:mvn/version "1.10.520"}
              com.bhauman/figwheel-main {:mvn/version "0.2.0"}
              nrepl/nrepl               {:mvn/version "0.8.3"}
              cider/cider-nrepl         {:mvn/version "0.25.8"}
              cider/piggieback          {:mvn/version "0.4.2"}}}

I don't think the Figwheel portion is affecting cider's attempts to connect. But I'm including it just for context.

(defn -main [& args]

  ;; Start Figwheel Server
  (figwheel.main.api/start
    {:mode :serve} "dev")


  ;; Start nREPL
  (def server (nrepl.server/start-server
                :port 1234
                :handler
                (fn [_]
                  (nrepl.server/default-handler cider.nrepl/cider-middleware))))


  ;; Start Figwheel REPL
  (fig/cljs-repl "dev"))
question from:https://stackoverflow.com/questions/66057626/cider-connect-clj-cannot-connect-to-nrepl-server-start-server

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It seems that you're starting the nREPL on port 1234, but then Emacs is trying to connect to port 6776. Could that be the reason?

When you run cider-connect-clj?you can select the port you want connect to. Try changing the default port to 1234 and see if that helps.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...