ClojureScript REPL not prompting after printing

Finally giving it a shot to ClojureScript.

Following the Tutorial.

The command

clj --main cljs.main --compile hello-world.core --repl
  1. Does open my browser showing me the Welcome page
  2. Does print Hello World
  3. Does Not promt me the REPL

I tried

clj --main cljs.main

And same result.

In all cases, refreshing the page just prints again “Hello World”. And if I refresh many times quickly I can cause an Exception: java.net.SocketException: Broken pipe (Write failed), that I suppose is an expected behavior.

I honestly don’t know how to troubleshoot this better as I’m just learning it.

What do you think I should review, try, etc.?

Try shadow-cljs please if it’s your first time playing with ClojureScript.

I don’t know how to fix the Broken pipe problem though…

1 Like

Try the following

$ mkdir temp
$ cd temp
$ mkdir -p hello-world/src/hello_world; printf "(ns hello-world.core)\n\n(js/console.log \"hello\")\n" > hello-world/src/hello_world/core.cljs; cd hello-world; clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.516"}}}' --main cljs.main --compile hello-world.core --repl

At this point Chrome opens, showing “Welcome to the ClojureScript browser REPL”. If for some reason the browser doesn’t open automatically, you can manually open http://localhost:9000 in your favorite browser.

If you switch back to your terminal and wait a few seconds, you should get a REPL prompt. The reason why it takes a little while is that the browser makes a connection back to the server.

At this point you can evaluate expressions:

ClojureScript 1.10.516
cljs.user=> cljs.user=> (+ 2 3)
5
cljs.user=> (js/console.log "works")
nil

If you type these commands, you should see “works” in the Chrome console.

If the above steps don’t work for you, please provide more information about which step fails and which OS or browser you’re using.

3 Likes

This question is about the official tutorial. Better than “try a different tool” is a reply that addresses the OP’s problem.

2 Likes

The result of following your instructions was:

  1. The browser opened with the welcome message
    1.1 In the browser console I can see the “Hello” message
  2. The REPL is not prompting

I’m using:

  • Ubuntu 16.04.6 LTS
  • Browsers:
    • Firefox Developer Edition 68.0b14 (64-bit)
    • Chrome 74.0.3729.169 (Official Build) (64-bit)
  • Java
    • 1.8.0_212
    • 11.0.3

I tested with the 4 combinations (Firefox, Java 1.8) (Firefox, Java 11) (Chrome, Java 1.8) (Chrome, Java 11), and the result is the same, I don’t get the REPL back.

Aside:

Another experiment I tried was to use an older version of ClojureScript. But simply changing 1.10.516 to 1.9.946 gives me this error:

Exception in thread "main" java.io.FileNotFoundException: Could not locate cljs/main__init.class, cljs/main.clj or cljs/main.cljc on classpath.

The same for 1.8.51. Looks like the only versions that will not rise that FilenotFound is the 1.10 onward.

But this is not the current problem anyways, I’m still trying to get the REPL.

Hm :slight_smile:

Those combinations should all work.

Have you tried pressing return in the terminal or typing [RETURN] (+ 1 2) [RETRUN]?

Do you see any errors in the devtools console? If there’s a problem, I’d expect some kind of network error or exception.

Also make sure that you have the latest version of the clojure cli tools installed:

 clojure -Sverbose
version      = 1.10.1.458
install_dir  = /usr/local/Cellar/clojure/1.10.1.458
config_dir   = /Users/pe/.clojure
config_paths = /Users/pe/.clojure/deps.edn deps.edn
cache_dir    = /Users/pe/.clojure/.cpcache
cp_file      = /Users/pe/.clojure/.cpcache/3742075259.cp

Yes I tried that. Your code gave me the Idea. In fact I tried to log something in the console but no luck with that.

I have not the latest version of clojre cli tool. I get this verbose information:

version      = 1.10.0.442
install_dir  = /usr/local/lib/clojure
config_dir   = /home/USER/.clojure
config_paths = /usr/local/lib/clojure/deps.edn /home/USER/.clojure/deps.edn deps.edn
cache_dir    = /home/USER/.clojure/.cpcache
cp_file      = /home/USER/.clojure/.cpcache/1214019075.cp

I’ll upgrade it and let you know.

Thank you.

So I updated Clojure to the 1.10.1.458 and nothing.

But, 2 things:

First, I tried in another machine and it worked:

  1. Kubuntu 18.04.2 LTS
  2. Firefox Quantum 670.4
  3. OpenJDK 10.0.2
  4. Bash 4.4.19

The Bash I’m using in my machine is 4.3.48

Second. One thing I noticed is that if a stop the unresponsive process in the terminal (Ctrl-C) the browser also closes. But in the other machine, closing the REPL, and/or stoping it with multiple Ctrl-C, doesn’t close the browser.

Third: --verbose in the Closurescript command in both environments don’t differ.
But here is the info:

My machine:

REPL env options: {:output-dir "/tmp/out345690582998353986542801279560381"}
Reading analysis cache for jar:file:/home/monkey/.m2/repository/org/clojure/clojurescript/1.10.516/clojurescript-1.10.516.jar!/cljs/core.cljs
Options passed to ClojureScript compiler: {:output-dir "/tmp/out345690582998353986542801279560381", :closure-warnings {:check-types :off, :check-variables :off}, :closure-defines {}, :ups-libs nil, :cache-analysis true, :closure-module-roots [], :optimizations :none, :ups-foreign-libs [], :verbose true, :aot-cache true, :preloads [process.env clojure.browser.repl.preload process.env clojure.browser.repl.preload], :ignore-js-module-exts [".css"], :source-map-inline true, :preamble ["cljs/imul.js" "cljs/imul.js"], :browser-repl true, :ups-externs nil, :opts-cache "brepl_opts.edn", :source-map true, :cache-analysis-format :transit, :emit-constants nil}


A LOT OF COPIES THEN

Other machine

REPL env options: {:output-dir "/tmp/out646785636374519152525988751091818"}
Reading analysis cache for jar:file:/home/jgomez/.m2/repository/org/clojure/clojurescript/1.10.516/clojurescript-1.10.516.jar!/cljs/core.cljs
Options passed to ClojureScript compiler: {:output-dir "/tmp/out646785636374519152525988751091818", :closure-warnings {:check-types :off, :check-variables :off}, :closure-defines {}, :ups-libs nil, :cache-analysis true, :closure-module-roots [], :optimizations :none, :ups-foreign-libs [], :verbose true, :aot-cache true, :preloads [process.env clojure.browser.repl.preload process.env clojure.browser.repl.preload], :ignore-js-module-exts [".css"], :source-map-inline true, :preamble ["cljs/imul.js" "cljs/imul.js"], :browser-repl true, :ups-externs nil, :opts-cache "brepl_opts.edn", :source-map true, :cache-analysis-format :transit, :emit-constants nil}

A LOT OF COPIES THEN

I’m suspecting is something with the Shell itself. I remember that certain RVM (Ruby) comands didn’t returned the control immediately. What other component shall I check? Is there a way to get more “verbose” info?

I don’t know exactly what it is, but, I created a new user and tried there, and it worked. So there must be something weird with my init files or the terminal configuration.

Thank you for your help.

It was nothing to do with my init files.

I can reproduce easily the problem now.

  • If the “favorite browser” is not already running, then the described problem happens. [The Problem]
  • If the “favorite browser” is already running, then the REPL appears.

Another thing I learned:

  • If I start Firefox with -no-remote, AND it is the favorite browser, not only the REPL will not appear, but this time I’ll receive the “Firefox is already running but is not responding” error message.

For now I’m conformant with the solution (keep the browser alive), but probably CLJS people would be interested in this problem.

Thank you for your support.

1 Like

I suggest filing a ticket. See https://clojurescript.org/community/reporting-issues

1 Like

I already filed a ticket long time ago. Sorry I’m on mobile it’s a bit tedious to find. Hope it will get some attention!

What did you file? Exactly the described issue - Ubuntu + the default browser not running?

Looks like “Your(my) email address … doesn’t have access to clojure.atlassian.net

And in the Github CLJS repository there is no “issue” tab.

Hope the ticket @DjebbZ mentions helps.

All Clojure core/Contrib projects use JIRA for issues https://clojure.atlassian.net/projects/CLJS/issues

I looked for @DjebbZ’s CLJS issue there but couldn’t find it.

Not Ubuntu, Arch Linux. But a colleague is on Ubuntu and had the same issue, no repl.

Can’t find it either… Maybe it was lost in the migration. I’m sure I had filed one.

Indeed. I just realize that my account didn’t survive the Jira migration… My username is now “Import” in the tickets I created. @alexmiller I think I need you help.

–edit: After spending some time on desktop I didn’t find the ticket in JIRA (maybe I never actually created it), but found this ticket from @mfikes that looks very similar, if not the same. @jgomo3 maybe you could look at it ? JIRA ticket: https://clojure.atlassian.net/browse/CLJS-3004

Not the same because I tried the instruction that says “works” but in my case doesn’t work if my favorite browser is not already running.

I could file the ticket, but as I mentioned before, I have no permission to do so, or something. Jira says to me Your email address … doesn’t have access to clojure.atlassian.net.

I suppose I have to ask somebody for permission.