shadow-cljs

kokonut 2025-04-16T04:28:42.474079Z

Hi, I am practicing to import JS/TS libraries into cljs project. I am using react-aria-components and it seems I am stuck in the beginning. Its repo is here https://github.com/adobe/react-spectrum/tree/main/packages/react-aria-components And the project is defined as react-aria-components according to its package.json file. https://github.com/adobe/react-spectrum/blob/main/packages/react-aria-components/package.json

{
  "name": "react-aria-components",
  "version": "1.8.0",
  "description": "A library of styleable components built using React Aria",
So, in my project I did my step one, yarn add react-aria-components . As a result this my dependency list.
"dependencies": {
        "react": "^17.0.1",
        "react-aria-components": "^1.8.0",
        "react-dom": "^17.0.1",
        "uri-js": "^4.4.1"
    }
I wanted to try a simple component, button. Its tsx file is defined here. https://github.com/adobe/react-spectrum/blob/main/packages/react-aria-components/src/Button.tsx But when I added the dependency in my ns require,
(ns client.pages.landing
  (:require
   ["react-aria-components"] or ["react-aria-components" :as aria] or ["react-aria-components" :refer [Button]] 
   [client.components :as com]))
I get the following errors.
[:app] Build failure:
The required JS dependency "react-aria-component" is not available, it was required by "client/pages/landing.cljs".
Dependency Trace:
	client/core.cljs
	client/pages/landing.cljs
But of course my node_modules folder has react-aria-component and the content in its dist folder. Can someone share thoughts on why this is happening? Thanks. (If you think this is more about reagent topic, let me know - i will move)

kokonut 2025-04-16T11:00:00.242249Z

You are right. At first the require section said "react-aria-component" and that caused this issue. Sorry for confusing. I fixed it to

(ns client.pages.landing
  (:require
   ["react-aria-components" :as rac]
   [client.components :as com]))

(defn core []
  [:div
   [:p "hello"]])
And it compiles fine, without showing any error on terminal
[:app] Compiling ...
[:app] Build completed. (1499 files, 2 compiled, 0 warnings, 0.28s)
But it crashes on the browser (please see the attached screenshot), and nothing renders on the screen. Hmm, maybe this is a reagent issue.

thheller 2025-04-16T11:01:29.987229Z

can't see how you used it in that code snippet. basically the error is [:> rac/something ...] with rac/something not existing

thheller 2025-04-16T11:01:45.574909Z

essentially [:> nil ...]. which is invalid and what the error message is telling you

kokonut 2025-04-16T11:04:20.519169Z

Yes, exactly. Only thing I did in my cljs (any cljs file for this regard) is just adding this line ["react-aria-components"] or ["react-aria-components" :as rac] I didn't even try [:> or adapt-react-class anywhere.

thheller 2025-04-16T11:05:29.561379Z

it might not be related to that at all. look at the error message. client.core/current-page is where the problem is. something with routing data given the reitet reference

kokonut 2025-04-16T11:07:44.082529Z

Yes, I am wondering that - not sure why. Without ["react-aria-components"] everything works normally. Btw, this is my core ns. Quite simple setting. To me it looks nothing would be related to this dependency.

(defonce match (r/atom nil))

(defn current-page []
  (when @match
    (let [view (:view (:data @match))]
      [view @match])))

(def routes
  [["/"
    {:name :client.route/landing
     :view landing-pg/core}]
   ["/about"
    {:name :client.route/about
     :view about-page/core}]
   ["/signup"
    {:name :client.route/signup
     :view signup-pg/core}]
   ["/login"
    {:name :client.route/login
     :view login-pg/core}]
   ["/dashboard"
    {:name :client.route/dashboard
     :view dashboard-pg/core}]])

(defn start []
  (rtfe/start!
    (rtf/router routes {:data {:coercion rtcs/coercion}})
    (fn [m] (reset! match m))
    {:use-fragment true})
  (rgd/render
   [current-page]
   (.getElementById js/document "app")))

(defn ^:export init []
  (start))

thheller 2025-04-16T11:08:43.306689Z

so inspect routes in the repl or tap> it and look at in the inspect UI. I bet one of those :view values is nil

thheller 2025-04-16T11:09:25.926479Z

could be caused by some other error during load. is there another error prior to the one in the screenshot above?

kokonut 2025-04-16T11:13:52.385089Z

Yep, you are right. I evaluated the routes in both cases. Landing page's view is nil in that case.

kokonut 2025-04-16T11:15:07.394279Z

In other words, landing-pg/core evaluates to nil.

thheller 2025-04-16T11:20:49.882589Z

so what is landing-pg/core? 😛

thheller 2025-04-16T11:21:14.698079Z

are there any other warnings/errors? I mean something must be happening. just adding the require shouldn't do anything

thheller 2025-04-16T11:22:12.857849Z

unless of course you have some sort of dependency conflict somewhere and maybe have 2 separate react versions on the page? maybe create a build report and look for red stuff (duplicates) https://shadow-cljs.github.io/docs/UsersGuide.html#build-report

kokonut 2025-04-16T11:25:26.674689Z

Yep, landing-pg/core is from

(ns client.core
  (:require
   [client.events]
   [client.pages.about :as about-page]
   [client.pages.dashboard :as dashboard-pg]
   [client.pages.landing :as landing-pg]
   [client.pages.signup :as signup-pg]
   [client.pages.login :as login-pg]
   [day8.re-frame.http-fx]
   [common.data]
   [reagent.core :as r]
   [reagent.dom :as rgd]
   [reitit.frontend :as rtf]
   [reitit.frontend.easy :as rtfe]
   [reitit.coercion.spec :as rtcs]))
And it refers to
(ns client.pages.landing
  (:require
   ["react-aria-components"] ;; -> problematic when included
   [client.components :as com]))

(defn core [] ;; -> this becomes nil when the problematic line is present
  [:div
   [:p "hello"]])

thheller 2025-04-16T11:26:24.597299Z

you keep evading my question if there are any other warnings/errors in the browser console? 😛

thheller 2025-04-16T11:26:55.579609Z

I find it hard to believe that stuff just breaks silently and stuff just ending up nil that clearly isn't

kokonut 2025-04-16T11:28:28.253029Z

Sorry, yes I found there are other warnings/errors on the browser console.

kokonut 2025-04-16T11:29:17.854869Z

Could be hard to read. The text (one of these) says

The above error occurred when loading "module$node_modules$$internationalized$date$dist$BuddhistCalendar_main.js". Any additional errors after that one may be the result of that failure. In general your code cannot be trusted to execute properly after such a failure. Make sure to fix the first one before looking at others. 

thheller 2025-04-16T11:30:08.575649Z

ok, so basically whenever there are errors in the console you cannot trust ANYTHING after that. it basically destroys everything

thheller 2025-04-16T11:30:21.079819Z

so, look at the very first and try to figure that one out

thheller 2025-04-16T11:30:31.550129Z

> In general your code cannot be trusted to execute properly after such a failure. Make sure to fix the first one before looking at others.

thheller 2025-04-16T11:30:33.654709Z

you know 😛

thheller 2025-04-16T11:31:03.080779Z

I'm unsure what the error is exactly

thheller 2025-04-16T11:33:40.894449Z

I just tested locally and react-aria-components loads just fine without any errors

thheller 2025-04-16T11:33:57.324949Z

could be a version conflict of some kind? which shadow-cljs version do you use?

kokonut 2025-04-16T11:35:36.740779Z

Yes, the very first one says

SyntaxError: missing { before class body
    globalEval 
    evalLoad 
    <anonymous> 
 main.js:1450:15
    reportError 
    evalLoad 
    <anonymous> 
The above error occurred when loading "module$node_modules$$internationalized$date$dist$JapaneseCalendar_main.js". Any additional errors after that one may be the result of that failure. In general your code cannot be trusted to execute properly after such a failure. Make sure to fix the first one before looking at others.
And this captures my attention "module$node_modules$$internationalized$date$dist$JapaneseCalendar_main.js" . Is it normal to say $$? My node_modules doesn't seem to have internationalized

kokonut 2025-04-16T11:36:46.942499Z

Please disreagrd. It has @internationalized

thheller 2025-04-16T11:37:05.601609Z

module$node_modules$$internationalized$date$dist$JapaneseCalendar_main.js is the "normalized" name for a node_modules file. basically it is node_modules/@internalionized/data/dist/JapaneseClendar_main.js

kokonut 2025-04-16T11:37:17.679499Z

You are right.

thheller 2025-04-16T11:37:31.640619Z

so a direct or indirect dependency of some of your code

thheller 2025-04-16T11:37:37.978069Z

which shadow-cljs version?

kokonut 2025-04-16T11:38:27.909729Z

"2.17.8"

thheller 2025-04-16T11:38:42.751159Z

that is very old. try upgrading.

kokonut 2025-04-16T11:42:13.602989Z

Sure. Upgraded to 2.28.23.

kokonut 2025-04-16T11:46:28.219549Z

Oh! It works now. No errors anywhere. My bad, I should have upgraded the main tool.

👍 1
kokonut 2025-04-16T11:47:23.931689Z

Thanks for your help @thheller

thheller 2025-04-16T06:15:10.422009Z

The error should also tell you where it looked for the files? does that list the folder the files are actually in?

thheller 2025-04-16T06:15:20.092929Z

should vome after Dependency Trace:

thheller 2025-04-16T06:15:56.897489Z

it should be /node_modules, if its somewhere else shadow-cljs needs to be configured to look there

thheller 2025-04-16T06:17:21.104329Z

or which one is it actually?

thheller 2025-04-16T06:17:35.018549Z

"react-aria-component" or "react-aria-components" not the missing s?