Welcome! Please see the About page for a little more info on how this works.

0 votes
in ClojureScript by
recategorized by

I am a Clojure noob and trying to learn the clj tool. I was following this https://betweentwoparens.com/start-a-clojurescript-app-from-scratch tutorial and at the command clj -A:dev got the following error:

Downloading: com/google/protobuf/protobuf-java/3.0.2/protobuf-java-3.0.2.jar from central
Downloading: com/google/code/findbugs/jsr305/3.0.2/jsr305-3.0.2.jar from central
Downloading: com/google/code/gson/gson/2.7/gson-2.7.jar from central
Exception in thread "Thread-4" java.net.SocketException: Broken pipe (Write failed)
    at java.base/java.net.SocketOutputStream.socketWrite0(Native Method)
    at java.base/java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:110)
    at java.base/java.net.SocketOutputStream.write(SocketOutputStream.java:150)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at clojure.lang.Reflector.invokeMatchingMethod(Reflector.java:167)
    at clojure.lang.Reflector.invokeInstanceMethod(Reflector.java:102)
    at cljs.repl.server$send_and_close.invokeStatic(server.clj:168)
    at cljs.repl.server$send_and_close.invoke(server.clj:144)
    at cljs.repl.browser$send_static.invokeStatic(browser.clj:205)
    at cljs.repl.browser$send_static.invoke(browser.clj:178)
    at cljs.repl.server$dispatch_request.invokeStatic(server.clj:191)
    at cljs.repl.server$dispatch_request.invoke(server.clj:182)
    at cljs.repl.server$handle_connection.invokeStatic(server.clj:199)
    at cljs.repl.server$handle_connection.invoke(server.clj:195)
    at cljs.repl.server$server_loop$fn__68.invoke(server.clj:209)
    at clojure.core$binding_conveyor_fn$fn__5754.invoke(core.clj:2030)
    at clojure.lang.AFn.run(AFn.java:22)
    at java.base/java.lang.Thread.run(Thread.java:834)

Why am I getting this error? My environment:

Ubuntu 18.04 in VirtualBox headless on Mac OSX Mojave.

[I] /home/user/tallex~> java -version
openjdk version "11.0.6" 2020-01-14 LTS
OpenJDK Runtime Environment Corretto-11.0.6.10.1 (build 11.0.6+10-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.6.10.1 (build 11.0.6+10-LTS, mixed mode)

I also tried this with:

[I] /home/sporty/software~> java -version
openjdk version "11.0.6" 2020-01-14
OpenJDK Runtime Environment (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.6+10-post-Ubuntu-1ubuntu118.04.1, mixed mode, sharing)

The result is the same.

EDIT: This has to do with the CLJ not being able to open up a browser because I am running Ubuntu headless. So I added port forwarding to the host and it seems to bring up X windows browser.

1 Answer

0 votes
by

This is because of running on headless virtual machine. When I added port forwarding to VirtualBox, it seemed to bring up the browser, but the REPL does not come up.

by
What page do you see in the browser?
by
In the browser, I do see the page that is shown on the Tutorial with the *Time Dive* in pink to red gradient.
by
I got the same issue with the very basic `clj -M -m cljs.main -r` on linux.

The official clojurescript quick start guide has the solution:
https://clojurescript.org/guides/quick-start

> If you are running Linux and the REPL does not start, try disabling browser auto-launch and opening http://localhost:9000 manually.

it means passing the `--repl-opts "{:launch-browser false}"` option in the command
[More about browser repl options](https://clojurescript.org/reference/repl-options#_browser_repl_options)

So in your case you should edit the `:dev` alias in `deps.edn` to look like:

(not tested)

```
:aliases
 {:dev {:main-opts ["-m"  "cljs.main"
                    "-ro" "{:static-dir [\".\",\"out\",\"resources\"], :launch-browser false}"
                    "-w"  "src"
                    "-c"  "tallex.time-dive"
                    "-r"]}}}
```
...