Fork me on GitHub

A while ago I discussed here some of the issues around targeting ES modules (which nbb does) and the necessity of having people add $default to their namespace names. There seemed to be no way around this since the JS world imposed this breakage and it would be highly disputable if a tool like nbb would have to "compensate" for that. Also when targeting ES modules with shadow (via :target :esm ) you end up with the exact same $default stuff, so at least it's compatible from that perspective (although vanilla CLJS currently doesn't emit ES modules). So with that settled, someone wrote a multi-namespaced project which consumes node libraries, but he (@chris358) tried to make it work with both shadow-cljs (target node-script) and nbb, but then this CJS vs. ESM stuff came up again. I believe I've found a workaround for this situation by • introducing reader conditionals for nbb :

#?(:org.babashka/nbb  ["cookie-parser$default" :as r-cookies] 
    :cljs ["cookie-parser" :as r-cookies])
• moving all dep imports to an isolated .cljc namespace (so you don't have to deal with this boilerplate in every ns and you don't have to turn all your .cljs files into .cljc files) • re-export the deps using vars: ◦ (def cookies r-cookies) • and then referring to the deps as (:require [deps :refer [cookies]) , (.foobar cookies ...) Full example: Just sharing this FYI. Perhaps reader conditionals can be used for similar purposes in the future to mitigate these incompatibilities in the JS ecosystem.