Third Party Libraries In Clojurescript REPL

I ran into an issue at work earlier this week. I needed to include a phone number validation library in the Clojurescript side. It was libphonenumber by Google, which meant it was compiled with the Google closure library.

Great! That gets us halfway there.

That classifies it as a third party library, meaning in lein-cljsbuild you would specify it under the :libs key instead of the :preamble, :externs, or :foreign-libs.

I just want to make it clear that the :foreign-libs option is used for non Google closure code like jquery.

So if you're using lein-cljsbuild, it's just as easy as putting the directory path into :libs in a vector. But my problem was that I needed to access the third party library in my Clojurescript REPL while developing.

Under this documentation, it says:

Note: conveying the :libs option to the REPL so that it can find third-party JavaScript libraries has not yet been implemented.

I've found that to be untrue for the Rhino and Nashorn case, and I'm not completely sure if it'll work in every single scenario yet so I'm hesitent to just change the wiki. I plan on doing some more investigation and then updating the wiki so other folks that come across this entry later won't waste their time looking into the source code like I had to.

An example of how to use this with piggieback as the nrepl middleware:

(require 'cemerick.piggieback 'cljs.repl.rhino)
(cemerick.piggieback/cljs-repl (cljs.repl.rhino/repl-env) :libs ["resources/js"])

Join the 80/20 DevOps Newsletter

If you're an engineering leader or developer, you should subscribe to my 80/20 DevOps Newsletter. Give me 1 minute of your day, and I'll teach you essential DevOps skills. I cover topics like Kubernetes, AWS, Infrastructure as Code, and more.

Not sure yet? Check out the archive.

Unsubscribe at any time.