I’m trying to shift clojurescript project from lein + fighwheel setup to shadow cljs. While trying to build I’ve encountered bulid failure with following error message
failed to require macro-ns "my.common.cljc.namespace", it was required by "my.cljs.namespace"
Syntax error macroexpanding clojure.core/ns.
Call to clojure.core/ns did not conform to spec.
-- Spec failed --------------------
(... ... (:require-macros ...) ...)
^^^^^^^^^^^^^^^
should be one of: :gen-class, :import, :load, :refer, :refer-clojure, :require, :use
So I have macro defined in the my.common.cljc.namespace which I’m using in the my.cljs.namespace.
it looks like this
(:require-macros
[swiss.arrows :refer [-<>> -<>]]
[my.common.cljc.namespace :refer [my-custom-macro-fn]]
[async-error.core :refer [go-try ]])
So, I digged around a bit and looks like :require-macros are not supported maybe? (I might be wrong here)
So, I changed the above code to
(:require
[swiss.arrows :refer-macros [-<>> -<>]]
[my.common.cljc.namespace :refer-macros [my-custom-macro-fn]]
[async-error.core :refer-macros [go-try ]])
Now that synatx error is gone but now facing another error regarding swiss.arrows as follows.
[:app] Build failure:
The required namespace "swiss.arrows" is not available, it was required by "autosched/web/rev_ai/crm_utils.cljs".
"swiss/arrows.clj" was found on the classpath. Should this be a .cljs file?
I’m quite new to clojure and clojurescript. Help me understand how macros are processed by compiler and what can I change so that build get’s built successfully.
Other details
cljs: 1.10.597
clj: 1.10.1
shadow-cljs 2.8.2why are you migrating to an ancient shadow-cljs version? should really be using 3.0.4, or if you can't do java21+ yet use 2.28.23
I wrote a bit about macros https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html
basically :require-macros exists and works, but shouldn't be used
Call to clojure.core/ns did not conform to spec.
-- Spec failed --------------------
(... ... (:require-macros ...) ...)
^^^^^^^^^^^^^^^
should be one of: :gen-class, :import, :load, :refer, :refer-clojure, :require, :useis telling you that Clojure (not clojurescript) didn't like that ns form. clojure indeed doesn't have :require-macros and it won't work there
if you are trying to use this https://github.com/rplevy/swiss-arrows then this won't work either. appears to be a CLJ only library with no support for CLJS
Thank you so much for the detailed explaination. I’ll shift to 2.28.23 version of the shadow cljs. The reason I was using the ancient version is because the current codebase needs Clojurescript version 1.10.597. But I’ll try the 2.28.23 and adjust clojure and clojurescript version accordingly. Let me also go through the macros guide. So that I can understand and make necessary changes. > if you are trying to use this https://github.com/rplevy/swiss-arrows then this won’t work either. appears to be a CLJ only library with no support for CLJS This is slightly confusing for me. In the existing codebase, under CLJS namespace they are imported as (:require-macros) and it works with figwheel. Is this the restriction applied in shadow cljs compilation or Am I missing something here?
ah ok. I only say that the file only had a .clj file. I didn't realize it was only macros
in that case :require-macros should be fine
and you can't adjust the clojure/clojurescript versions. you need to pick the exact version 2.28.23 needs.
if you wanted to use it "like any other namespace" you could just create a swiss/arrows.cljs file in your classpath with just (ns swiss.arrows (:require-macros [swiss.arrows]))
then all other namespaces can just (:require [swiss.arrows :refer (whatever)]) like everything else. no need for :require-macros or :refer-macros beyond that one point
Got it. Things are now clear for me. I’ll definitely make this changes. And will try to compile build. Thank you for all the inputs 🙂
why do you need an old cljs version? did that ever break anything when going to new version?
Not yet. But my gut feeling was let’s switch to shadow cljs first and then will upgrade to latest clojurescript/clojure version
all this should really work exactly like in figwheel, unless you were relying on a specific bug in figwheel/cljs before 😛
much easier to do it all at once
I mean I tried to improve things in shadow-cljs over time, so error messages and behavior should be better the newer it gets
OK, will try that then. Thanks 👍