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)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.can't see how you used it in that code snippet. basically the error is [:> rac/something ...] with rac/something not existing
essentially [:> nil ...]. which is invalid and what the error message is telling you
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.
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
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))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
could be caused by some other error during load. is there another error prior to the one in the screenshot above?
Yep, you are right. I evaluated the routes in both cases. Landing page's view is nil in that case.
In other words, landing-pg/core evaluates to nil.
so what is landing-pg/core? 😛
are there any other warnings/errors? I mean something must be happening. just adding the require shouldn't do anything
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
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"]])you keep evading my question if there are any other warnings/errors in the browser console? 😛
I find it hard to believe that stuff just breaks silently and stuff just ending up nil that clearly isn't
Sorry, yes I found there are other warnings/errors on the browser console.
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. ok, so basically whenever there are errors in the console you cannot trust ANYTHING after that. it basically destroys everything
so, look at the very first and try to figure that one out
> 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.
you know 😛
I'm unsure what the error is exactly
I just tested locally and react-aria-components loads just fine without any errors
could be a version conflict of some kind? which shadow-cljs version do you use?
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 internationalizedPlease disreagrd. It has @internationalized
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
You are right.
so a direct or indirect dependency of some of your code
which shadow-cljs version?
"2.17.8"that is very old. try upgrading.
Sure. Upgraded to 2.28.23.
Oh! It works now. No errors anywhere. My bad, I should have upgraded the main tool.
Thanks for your help @thheller
The error should also tell you where it looked for the files? does that list the folder the files are actually in?
should vome after Dependency Trace:
it should be , if its somewhere else shadow-cljs needs to be configured to look there
or which one is it actually?
"react-aria-component" or "react-aria-components" not the missing s?