Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Debug ClojureScript

I apologize for this seemingly stupid question, but I've been playing with ClojureScript on and off for a few weeks now, and I can't figure out this one simple question:

How do I debug ClojureScript?

So here is the problem:

  1. I write my *.cjs files
  2. I run cljsc/build ...
  3. I load up my webpage.
  4. Something bad happens.
  5. I open up the firefox console.
  6. I get a line in the generated js, which I find incomprehensible, and I have no idea which line of the original cljs file it came from.

My question:

What is the right way to develop ClojureScript applications?

PS I've looked at ClojureScriptOne -- what I don't like about it is that it strings together a bunch of technology all at once; and I'd prefer to understand how to use each individual piece on its own before chaining it all together.

I'm comfortable with ring + moustache + compojure, [mainly because I can use my standard Clojure debugging techniques] but ClojureScript is another beast.

UPDATE: Things have changed quite a bit since this question was first asked. The proper way to debug ClojureScript applications these days is to enable source maps - http://github.com/clojure/clojurescript/wiki/Source-maps

like image 897
user1383359 Avatar asked Jun 12 '12 03:06

user1383359


4 Answers

UPDATED: Using the compiler directly is now straightforward. But lein-cljsbuild is still very useful.

Use lein-cljsbuild. You can write different builds (testing, development, release). You can auto-watch files so they recompile quickly as you change them. You can easily use browser repl to evaluate code directly in the browser. You can manage dependencies.

Specifically related to your question - lein-cljsbuild also passes along sensible warning defaults to the compiler so that you get verbose and accurate warnings before you actually run the code in the browser.

like image 173
dnolen Avatar answered Sep 20 '22 17:09

dnolen


UPDATE: I've taken the liberty to change the original answer since it is so woefully out of date and I cannot unmark this answer and mark a new one.

To debug ClojureScript use source maps - https://clojurescript.org/reference/source-maps

like image 28
Hendekagon Avatar answered Sep 20 '22 17:09

Hendekagon


Recently (Oct. 27 2013) David Nolen released a blog post suggesting a great setup for a tight feedback loop and a good debugging experience with ClojureScript.

http://swannodette.github.io/2013/10/27/the-essence-of-clojurescript/

"This short post will get you from zero to developing source mapped ClojureScript with instant recompiles on file save."

Hope that could also help.

like image 6
leontalbot Avatar answered Sep 23 '22 17:09

leontalbot


If you want to use Chrome Debugger, you can use the following...

(defn debugger []
  (js/eval "debugger"))

(debugger)

this is very much a hack, but it will active chrome's debug mode.

Remember though, Clojure Script uses namespaces, which means if you created some variable thing, then it will be found in my.namespace.thing in chrome console (as expected).

like image 6
film42 Avatar answered Sep 24 '22 17:09

film42