shadow-cljs

Kiran 2025-05-04T11:28:01.549119Z

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.2

thheller 2025-05-04T19:36:17.119199Z

why 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

thheller 2025-05-04T19:36:34.931449Z

I wrote a bit about macros https://code.thheller.com/blog/shadow-cljs/2019/10/12/clojurescript-macros.html

thheller 2025-05-04T19:36:46.247119Z

basically :require-macros exists and works, but shouldn't be used

thheller 2025-05-04T19:37:12.294019Z

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

thheller 2025-05-04T19:37:26.098769Z

is 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

thheller 2025-05-04T19:39:16.984239Z

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

Kiran 2025-05-05T04:57:28.501029Z

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?

thheller 2025-05-05T06:30:10.737539Z

ah ok. I only say that the file only had a .clj file. I didn't realize it was only macros

thheller 2025-05-05T06:30:18.579649Z

in that case :require-macros should be fine

thheller 2025-05-05T06:31:02.717539Z

and you can't adjust the clojure/clojurescript versions. you need to pick the exact version 2.28.23 needs.

1
thheller 2025-05-05T06:32:44.503989Z

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]))

thheller 2025-05-05T06:33:45.217799Z

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

Kiran 2025-05-05T06:36:01.389349Z

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 🙂

thheller 2025-05-05T06:36:07.355169Z

why do you need an old cljs version? did that ever break anything when going to new version?

Kiran 2025-05-05T06:37:05.315339Z

Not yet. But my gut feeling was let’s switch to shadow cljs first and then will upgrade to latest clojurescript/clojure version

thheller 2025-05-05T06:37:13.679299Z

all this should really work exactly like in figwheel, unless you were relying on a specific bug in figwheel/cljs before 😛

😛 1
thheller 2025-05-05T06:37:37.006439Z

much easier to do it all at once

thheller 2025-05-05T06:38:02.676029Z

I mean I tried to improve things in shadow-cljs over time, so error messages and behavior should be better the newer it gets

Kiran 2025-05-05T06:38:09.314069Z

OK, will try that then. Thanks 👍