Launching the ClojureScript REPL Browser

I am trying to run the ClojureScript REPL in a browser. Ideally, I would like not to use Austin yet: first I want the simplest REPL to work.

I've tried following various tutorials and so far I haven't been able to get it to work. Basically I don't understand what people mean when they say, "Run the ClojureScript REPL browser".

So far I have done:

lein new mies hellow



lein cljsbuild auto hellow


And here is my core.js file:

(ns hellow.core
  (:require [clojure.browser.repl :as repl]))


(println "Hello world!")    
(. js/console (log "Hello again"))    
(repl/connect "http://localhost:9000/repl")    
(. js/console (log "Ah, this prints too"))


When I open my index.html (which calls core.js) I can see in the Chrome developer console JavaScript console tools all spelled out correctly.

However (repl/connect ...)

, it obviously fails. Chrome developer tools are displayed here.

Failed to load resource http://localhost:9000/repl?xpc=%7B%22cn%22%...


In almost every ClojureScript forum / blog / tutorial I read about this topic, I come across a line that says "Start browser REPL" or something similar.

How do I start the REPL browser? Is this something to be done before loading index.html from the browser?

Can this REPL browser be run from Emacs?

How to check if browser REPL is running without loading index.html / core.js?

How can I check, after index.html / core.js is loaded in the browser, that (repl / connect ...) inside core.js is actually working and is actually connected to the REPL?


source to share

1 answer

The simplest and easiest way to start a repeater (you already include the client code) is doing

$ lein trampoline cljsbuild repl-listen
Running ClojureScript REPL, listening on port 9000.
To quit, type: :cljs/quit


At this point, if you try to evaluate any type expression (+ 1 2)

, for example, you will see that the variable hangs because it does not have an eval environment.

That when you go to the index.html ( remember to serve it from the webserver or the connection will fail, don't use the urls file:///

) and open it with a browser.

The connection with http://localhost:9000/repl?xpc=...

should work fine and repl should unlock and print 3

. From now on, any commands will be executed in the browser environment.

I like to try (js/alert "hi")

to see if repl is connected, if it works it will alert

hi in the browser window.

Remember that the browser window is your runtime, so if you refresh it, you will lose the runtime values ​​and they will not be available from repl unless you already define them.

Cljsbuild also has: ( lein cljsbuild help


  Run a REPL that will listen for incoming connections. (the one I used above)
  Run a REPL and launch a custom command to connect to it.
  Run a Rhino-based REPL (JVM based JS execution environment, no browser needed).


Also, for barebones replica it is useful to use it with rlwrap to get readline quick links (Ctrl + a, etc.) and restore history among other things:

$ rlwrap lein trampoline cljsbuild repl-listen


Hope this all helps.



All Articles