I'm trying to use ClojureScript for a project. To be a happy developer, I need a quick feedback-loop: write some code and see it as soon as it's possible. I'd also love to use REPL in the context of the current page.
I'm using lein-cljsbuild
and from the issues I'm having I think I failed to set it up properly.
First of all, compilation time for a small file is too big, even after "JWM warm-up" with :optimizations :simple
:
Compiling "resources/public/js/cljs.js" from ["src-cljs"]...
Successfully compiled "resources/public/js/cljs.js" in 8.233018 seconds.
Compiling "resources/public/js/cljs.js" from ["src-cljs"]...
Successfully compiled "resources/public/js/cljs.js" in 5.522989 seconds.
Compiling "resources/public/js/cljs.js" from ["src-cljs"]...
Successfully compiled "resources/public/js/cljs.js" in 8.144354 seconds.
Second, from time to time I get stuff like this:
Compiling "resources/public/js/cljs.js" from ["src-cljs"]...
Compiling "resources/public/js/cljs.js" failed.
Exception in thread "main" java.lang.NullPointerException
at java.util.regex.Matcher.getTextLength(Matcher.java:1140)
at java.util.regex.Matcher.reset(Matcher.java:291)
at java.util.regex.Matcher.<init>(Matcher.java:211)
at java.util.regex.Pattern.matcher(Pattern.java:888)
at clj_stacktrace.utils$re_gsub.invoke(utils.clj:6)
# ... many similar useless lines
at clojure.lang.Var.applyTo(Var.java:532)
at clojure.main.main(main.java:37)
These stacktraces (most of the time related to syntax errors, as I understood from experimenting), are worse than not helpful: not only they provide zero clues about the error, they also stop automatic recompilation. After every such stacktrace I should do these things:
- Figure out what's the problem, using a technique I call "pretend you're a parser". Thank God it's Lisp and the only thing I should do is to carefully count matching parentheses.
- Press
Cmd-C
in the shell where thelein cljsbuild auto
runs - Run
lein cljsbuild auto
again - Make some useless change, like inserting a newline, in the file, to trigger a new build
- Wait for ~30 seconds until the file is compiled again, since the JVM has to "warm-up" again
- In many cases at this point I get another stacktrace, after getting which I have to lather, rinse and repeat all the damned procedure
Third thing which I failed to understand is REPL. From the interwebs I've learned how to connect rlwrap lein trampoline cljsbuild repl-listen
to the current page. However, every reload, navigation, and syntax error (god forbid you forget to use rlwrap
and press an arrow key) in the console makes the REPL completely stuck. I have to restart it (~10 seconds) and reload the page after that, then start again trying stuff out in a friendly environment.
I think, probably someone has figured it all out and has a workflow that works. Please help me set it all up from the start, because I feel like a failed software engineer.