I am having the following common.cljc
:
(ns projectname.common
(:require [rum.core :include-macros true :as rum]))
(rum/defc my-comp [a f b]
[:div [:h1 a] [:h2 f] [:span b]])
which I inculde like this in my core.cljs
:
(ns projectname.core
(:require [rum.core :as rum]
[projectname.common :refer [my-comp]]))
(rum/hydrate (my-comp "3" "test" 3) (js/document.getElementById "app"))
But I always get this wired error (shadow-cljs):
2 | (:require [rum.core :include-macros true :as rum]))
3 |
4 | (rum/defc my-comp [a f b]
5 | [:div [:h1 a] [:h2 f] [:span b]])
---------------------^----------------------------------------------------------
Use of undeclared Var projectname.common/a
--------------------------------------------------------------------------------
Can someone please point me to my error?This is my deps.edn
:
{:paths ["src/clj" "resources", "src/cljc"]
:deps {org.clojure/clojure {:mvn/version "1.10.3"}
metosin/reitit {:mvn/version "0.5.2"}
http-kit/http-kit {:mvn/version "2.3.0"}
rum/rum {:mvn/version "0.12.4" :exclusions [cljsjs/react cljsjs/react-dom]}
}
:aliases {:run {:main-opts ["-m" "projectname.core"]}
:shadow-cljs
{:extra-deps {thheller/shadow-cljs {:mvn/version "2.11.26"}}
:extra-paths ["src/cljs/"]
:main-opts ["-m" "shadow.cljs.devtools.cli"]}}
}
Funnily enough, the .clj
code can import the cljc
file without problems. It must be something with ClojureScript and/or shadow-cljs (maybe some special config for .cljc
files?!)
It must have something to do with taking the wrong defc implementation when importing the cljc file from cljs. I guess some Readermacro ( #?(:cljs ... :clj ....) ) But I can not figure out how to make that work Please help 🙂
Even tried this:
(ns projectname.common
(:require #?(:cljs [rum.core :refer-macros [defc]]
:clj [rum.core :refer [defc]])))
(defc my-comp [a f b]
[:div "this comp is from cljc" [:h1 a] [:h2 f] [:span b]])
Still, I get:
1 | (ns projectname.common
2 | (:require #?(:cljs [rum.core :refer-macros [defc]]
3 | :clj [rum.core :refer [defc]])))
4 |
5 | (defc my-comp [a f b]
6 | [:div "this comp is from cljc" [:h1 a] [:h2 f] [:span b]])
----------------------------------------------^---------------------------------
Use of undeclared Var projectname.common/a
--------------------------------------------------------------------------------
I figured that the first render seems to work. It may not even be because of the .cljc
file.
Please see https://clojureverse.org/t/how-to-start-with-clj-shadow-cljs-rum/7403/5
just here to say that I also get this behavior on 0.12.4, but not on 0.12.3
thanks man, you're great 🙂