Fork me on GitHub
#calva
<
2022-02-14
>
fadrian15:02:35

I'm trying to get a shadow-cljs project running under Calva. Everything seems to be working up through jack-in, but when I look at the terminal output, I get the message:

[:app] Build failure:
The required namespace "atlas.main" is not available.
However, my .cljs file is set up in src/atlas/main.cljs and has the proper namespace declared:
(ns atlas.main)

(defn main![] 
  (println "Hello, world!"))

(defn reload! []
  (println "Code updated!."))
I believe my shadow-cljs.edn file is also set up correctly, with the following entries:
;; shadow-cljs configuration
{:source-paths
 ["src/dev"
  "src/atlas"
  "src/test"]

 :dependencies
 []

 :dev-http {32456 "public"}
 :builds
 {:app {:output-dir "public/js"
        :asset-path "."
        :target :browser
        :modules {:main {:init-fn atlas.main/main!}}
        :devtools {:after-load atlas.main/reload!}}}}
Any ideas why I'm getting the error during jack-in?

pez16:02:10

I think it is that you. have the source path src/atlas but in there you have main.cljs , then the namespace doesn't match the path. Try putting main.cljs in src/atlas/atlas/ .

pez16:02:36

You might also get away with having source-patsh ["src", "dev", "test"] and place atlas directories in src and test. (If you don't like the atlas/atlas layout.)

fadrian16:02:19

Thanks. Switching the source path to src worked.

pez16:02:05

Awesome. Can't tell you how often I have tripped on that.

agold19:02:27

I’ve tripped on it too. It happens because Calva helpfully infers the namespace without checking the src path specification in shadow-cljs.edn. It might be better if Calva checked that file on shadow-cljs projects or asked the user what the src path is before jumping to conclusions about what the ns should be. Just a thought.

pez20:02:33

Calva makes no assumptions here. You would end up in the same place just using shadow without any editor involved.

agold20:02:47

Calva suggests (ns atlas.main), but if it looked at shadow-cljs.edn, it would know that the src path was specified as src/atlas and could therefore suggest (ns main) instead. Or am I missing something? Not a big deal, of course, since once you’ve been bitten by this, you know immediately how to fix it.

pez20:02:37

Not sure Calva suggests that. Haven't tried. But if it does, it is clojure-lsp. 😃

agold20:02:34

:smiling_face_with_3_hearts:

pez20:02:06

atlas.main is indeed suggested. Should probably be filed as an issue on clojure-lsp.