Tip: Uncaught Invariant Violation

Uncaught Invariant Violation: onlyChild must be passed a children with exactly one child.

Are you using Reagent and Bootstrap with ClojureScript, and getting this error?

In my case, the cause was that I had a when inside an OverlayTrigger. Seems like a no-no. Further testing showed you can’t have an if either. Looks like OverlayTrigger can only wrap data, not something that might change.

In my case the solution was simple enough, once I figured out the cause: I just extracted when to wrap the OverlayTrigger, instead of the other way around.

ClojureScript tip: mind the Clojure version

Updated the ClojureScript version, and now you’re getting build errors? Check the Clojure version.

If you do an upgrade through lein ancient update, it will not upgrade the Clojure version. But if you have a ClojureScript dependency, it will be upgraded, and you may run into a case like this when building:

No such var: string/index-of, compiling:(cljs/source_map.clj:260:54)

I got this error when going from ClojureScript 1.8.34 to 1.9.93. I wasn’t using index-of directly, which is a Clojure 1.8 function… but ClojureScript was.

Extending types from Clojure while working on the REPL

On the datatypes chapter of Programming Clojure 2nd edition (page 155) there’s the following bit where the CryptoVault is extended to support the default input streams:

Book capture

The calls to spit/slurp didn’t work on my tests at first, even reloading the namespace.