shadow-cljs 2025-03-24

I've mentioned this problem some days ago: https://clojurians.slack.com/archives/C6N245JGG/p1742253581707129 I just wondered, is there a way to extract this code into a separate project, build an artifact from this that I can include in other projects to circumvent this? Sorry that this is such an open-ended question, my understanding of CLJS builds is still very limited. Basically, the entire interop I need with the vega libraries is just for building this single component. Alternatively, is there a way to disable/circumvent google closure compilation for just a single dependency?

I believe they provide a CDN variant, which you can just use and just not have vega in the build at all

following that you'd just use (js/vegaEmbed ..) in your code

so, basically yes, they already provide this for you ๐Ÿ˜›

if you don't want the CDN you probably can just use the files directly from npm

and include them via separate src tags?

well now I just feel stupid

Can I refer to this then? Or am I dependent on global objects defined by a library? Having this in index.html :


    
    
and this require:
["react-vega" :refer [VegaLite]]
unsurprisingly gives me
[:app] Build failure:
The required JS dependency "react-vega" is not available

you can configure shadow-cljs to redirect the react-vega to the global https://shadow-cljs.github.io/docs/UsersGuide.html#js-resolve

but that still means you are dependent on the globals provided by the lib, so might as well just use the globals via js/whatever

Thanks so much! I ended up triangulating an older version that doesn't give me all that headache (i.e. works with google closure and seems to support all the features I am interested in). It was not obvious to me what globals are exported by the respective packages anyway, whether those would "work" as expected etc.

yeah I hope the new closure compiler version fixes this, but it isn't available via maven. gotta wait a bit to find out I guess.

I take it if you have a test suite and run npx shadow-cljs watch :test` there is no way to pass CLI args to the test runner to only run a single namespace?

not currently no, but you can just not use :autorun and instead use something else that just runs the node command with some kind of trigger, e.g. watching the output file

Got it, I can just use nodemon for that, just wanted to make sure I wasn't missing something. Thanks!

Hi, I get a strange issue with react-scan npm package. I managed to reproduce on a bare reagent project create with lein new. ๐Ÿงต

It works great adding react-scan like this in the core namespace :

(ns reagent-scan.core
  (:require
   ["react-scan" :refer [scan]]
   [reagent.core :as r]
   [reagent.dom :as d]))

;; -------------------------
;; Views

(defn home-page []
  [:div
   [:h2 "Welcome to Reagent"]])

;; -------------------------
;; Initialize app

(defn mount-root []
  (d/render [home-page] (.getElementById js/document "app")))

(defn ^:export init! []
  (scan #js {:enabled true})
  (mount-root))

But when using Shadow options :deps true , scan return undefined and I get this error in the browser console :

Uncaught TypeError: module$node_modules$react_scan$dist$auto_global.scan is not a function

At first, I was thinking it's caused by a different Shadow-CLJS version and indirectly a different Closure version but both deps.edn and package.json had the same shadow-cljs version. ๐Ÿค”

OK, using yarn shadow-cljs info , I see the project using the last version of Shadow-cljs ignoring the package.json version.

unsure how this would affect anything in the code? it certainly won't affect the JS generated if you are indeed getting the exact same versions

its not ignoring anything unless you tell it to ๐Ÿ˜›

remember that changing the verison in package.json does nothing unless you actually run yarn install

I pretty sure, that I run rm -r node_modules && yarn install haha ! Maybe it's too late for my brain ๐Ÿ˜„

Maybe I missed something. On a fresh new project lein new reagent-frontend foobar , I have this version in package.json :

"shadow-cljs": "^2.19.2"

But running, yarn shadow-cljs info , I get :

=== shadow-cljs version (via npm)
shadow-cljs version:  2.28.21

It's why I said "ignoring".

"^2.19.2" that is a node version range, basically anything higher goes, as long as its 2.x

so that gives you the latest version whenever you install it and once installed it uses whatever is on the lock file

Indeed, Shadow-cljs is still version 2. ๐Ÿ‘ As usual, thank you @thheller for this reminder and you reactivity !

(same goes for the react-scan lib btw, so make sure you are actually working on the same version you have issues with)

๐Ÿ‘ 1

version ranges can really mess with you expectations here ๐Ÿ˜›

Yeah, the JS little pleasures. ๐Ÿ˜›