Search code examples
npmemacsclojurereagentcider

While developing Clojure, is running the dev environment with npm incompatible with Emacs Cider?


I am new to Clojure and not a pro in Javascript. I am watching the free part of the course on Reagent.

Following the instructions on the course's repo, after doing the git clone and the npm install, the author indicates running $ npm run dev. Everything works fine. I can see the app on my http://localhost:3000/.

Since I am a heavy user of Emacs, I decided to start Cider, an emacs package that makes Emacs an IDE for Clojure. Thus, I would do interactive programming with REPL.

After executing in Emacs cider-jack-in, an error is returned. Emacs indicates:

error in process sentinel: Could not start nREPL server: shadow-cljs - config: /home/pedro/projects/learn-reagent-course-files/giggin/shadow-cljs.edn shadow-cljs - connected to server server already running

While it is not possible to do cider-jack-in after npm run dev, it is possible to successfully use cider-jack-in. To do so, I just need to exit everything and without dealing with npm, simply execute cider-jack-in on the repo.

Why is this happening? Is Emacs cider incompatible with npm run dev? Incompatible with a server already running?

Concerning the error message content, what is the relation between Cider, the npm process, and shadow-cljs?


Solution

  • I cannot comment on any Cider/Emacs specific things since I don't use it myself. I can however attempt to maybe clear up what is is doing:

    npm run dev just runs npx shadow-cljs watch app (see package.json "scripts"). It is just an alias, making it a little shorter. So, it starts shadow-cljs and begins the app build compilation and keeps watching for changes.

    cider-jack-in on the other hand I believe also starts a fresh new JVM, which will be entirely independent and not aware or connected to the shadow-cljs processes started via npm run dev.

    It is possible to just use shadow-cljs from the REPL you get from cider-jack-in, but I don't know any specifics about what cider-jack-in may already be doing for you. Maybe the docs on REPL use can provide some help?

    You can instead also just skip cider-jack-in and instead have Cider connect to the shadow-cljs instances started by npm run dev. I believe that command is cider-connect.