Fork me on GitHub
#shadow-cljs
<
2022-10-25
>
Eric Dvorsak10:10:44

I declare my deps in deps.edn and I am trying to build with tools.build, when I call (shadow/release :main) in my build.clj I get "The required namespace is not available...", the being the first dependency required by my code, defined in the :deps key of my deps.edn. When I copy paste that dependency under :replace-deps of the :shadow-cljs alias then I get the same error with the next one (meaning that dependency is now visible to shadow/release). My question would be if that is expected? Is there a way to tell shadow-cljs to use the deps from deps.edn :deps key like it does during development?

Ferdinand Beyer10:10:30

> My question would be if that is expected? Yes. You are using tools.build with :replace-deps, so the Clojure CLI will build a classpath with only the defined deps, and then you use Shadow’s API within the same JVM, so Shadow will have the same classpath. You probably need to adjust your classpath and make sure that all ClojureScript deps are on the classpath as well, or spawn a sub-process from your build.clj to call Shadow with its own classpath.

Eric Dvorsak10:10:12

Initially I was not using :replace-deps I just added it to test if it will find the dependency that way

Eric Dvorsak10:10:34

:shadow-cljs
           {:paths ["src/main"]
            :extra-deps {thheller/shadow-cljs {:mvn/version "2.20.2"}}
            :main-opts ["-m" "shadow.cljs.devtools.cli"]}

Eric Dvorsak10:10:52

all the deps are in the :deps key

Ferdinand Beyer10:10:56

How are you using build.clj? Using clojure -T:build?

Eric Dvorsak10:10:13

clojure -T:shadow-cljs:build

Ferdinand Beyer10:10:24

How is your :build alias defined?

Eric Dvorsak10:10:39

:build {:deps {io.github.clojure/tools.build {:git/tag "v0.8.3" :git/sha "0d20256"}}
                   :ns-default build}

Ferdinand Beyer10:10:37

Not sure if -T will ignore the root-level :deps. In general, you should not use :deps in your aliases, but :extra-deps or :replace-deps. Normally, tools are meant to run in a classpath that is different from your project’s, so they use :replace-deps. In your case, can you try using :extra-deps in both your :build and :shadow-cljs aliases?

Ferdinand Beyer10:10:15

I see you have that in :shadow-cljs already

Ferdinand Beyer10:10:18

See the docs for -T: https://clojure.org/reference/deps_and_cli#_running_a_tool > When running a tool, the project’s :deps and :paths are not used.

Eric Dvorsak10:10:25

yeah will try, I didn't think too much about this one in :build, I took inspiration from https://github.com/metosin/packaging-clojure-examples/blob/master/deps-uberjar/deps.edn#L17

Ferdinand Beyer10:10:46

I think in your case you don’t want to use -T, as this is meant for standalone tools with their own classpath. Instead, if you use :extra-deps in the :build alias, you should be able to use the -X switch to run your build functions, with a classpath built from your project’s :deps and all extra deps from additional aliases.

Ferdinand Beyer10:10:14

You might need to add :extra-paths ["."] so that your build.clj in on the classpath. Note that: > Tools declared with an alias can also be executed with -T, just as they can be executed with -X. The only difference is that -T implies {:replace-deps {}, :replace-paths ["."]}, so the project deps/paths will not be included, by default.

Eric Dvorsak11:10:52

running with -X solved my issue

Eric Dvorsak11:10:04

So I assume what's missing is the possibility to pass a basis to shadow/release

Ferdinand Beyer11:10:31

I understand it this way: The shadow-API is meant to be used on a preconfigured classpath, and the standalone version will follow shadow-cljs.edn to deps.edn (when configured) and builds the basis

thheller17:10:16

yeah, tools.build doesn't use the project classpath but CLJS compilation (and therefore shadow-cljs) require access to the full project classpath

superstructor23:10:04

Is there a way to disable shadow-cljs automatically calling 'npm install...' commands if one does not want that behaviour ?

thheller05:10:31

:npm-deps {:install false} top level in shadow-cljs.edn