Fork me on GitHub
#clojurescript
<
2022-02-13
>
Zayn Malik12:02:53

Hello everyone, I am a beginner in Clojurescript and I am reading this book "Dmitri Sotnikov, Scot Brown - Web Development with Clojure_ Build Large, Maintainable Web Applications Interactively-Pragmatic Bookshelf". So I am making the Clojurescript project mentioned in it for practice but I am facing an error.

Caused by: java.io.FileNotFoundException: Could not locate guestbook/validation__init.class, guestbook/validation.clj or guestbook/validation.cljc on classpath.
I will explain the details in the reply section.

Zayn Malik12:02:15

The image of the source tree is attached. I also mentioned the source paths in the project.clj.

:cljsbuild 
  {:builds
   {:app {:source-paths ["src/cljs" "src/cljc"]
          :compiler {:output-to "target/cljsbuild/public/js/app.js"
                     :output-dir "target/cljsbuild/public/js/out"
                     :main "guestbook.core"
                     :asset-path "/js/out"
                     :optimizations :none
                     :source-map true
                     :pretty-print true}}}}

p-himik12:02:54

Are you sure that when building CLJS, you're using a command that ends up using the :app build specified in project.clj and not something else?

Zayn Malik13:02:11

I am using lein cljsbuild auto

p-himik13:02:21

No clue to be honest. I'd try to read the documentation of lein-cljsbuild and see if it has some kind of verbose mode or anything like it that would output the full classpath to double check that it's correct. I myself have moved away from anything lein-related a few years ago, so unfortunately can't really help beyond that suggestion.

Zayn Malik13:02:11

ohh, no problem. the error doesn't occur at the compile time. It occurs when I run the application using lein run.

p-himik13:02:00

Uhm... that's a completely different problem then. When you run something using lein, that's probably a CLJ project being run, not a CLJS one. Despite them being in the same directory tree, those two are different concepts, they work differently. Assuming we're talking about a regular web application, a CLJS app is first built from the sources, which ends up in a single JS file (multiple files in case of a development build). That JS file, assuming everything is setup up correctly, is run by your browser after the loaded HTML page has requested that JS file. So by running something with lein, you don't run your CLJS code but rather a CLJ one. If it needs to access that guestbook.validation namespace, then that file must also be on the CLJ classpath as the CLJS classpath is completely separate. What does your :source-paths look like outside of the :cljsbuild map?

Zayn Malik14:02:21

ohh alright, this is another source path

:source-paths ["src/clj"]

Zayn Malik14:02:28

so i have to include the other source paths here as well?

p-himik14:02:56

Only CLJ and CLJC. Clojure itself does not read CLJS files.

p-himik14:02:19

But the CLJS compiler of course must know about CLJS, CLJC, and CLJ files that it uses - usually for macros.

Zayn Malik14:02:47

ok alright, thank you

Zayn Malik14:02:50

it is working, thank you Eugene. your answers provide good insight and motivate me to learn more.

👍 1
p-himik19:02:31

If I have the org.clojure/clojurescript jar on classpath of a Clojure process, is there a more reliable way to get its version than to parse the (def *clojurescript-version* "1.10.914") form in cljs/core.cljs? Update: ah, we have cljs/util.cljc with the version as well, nice!

thheller19:02:24

the jar filename itself has the version?

p-himik19:02:11

The jar itself is problematic - not a flexible solution given how e.g. CLJS quickstart talks about downloading cljs.jar.

thheller19:02:44

does it still? thought that was replaced with deps.edn and cljs.main?

p-himik19:02:04

Nah, it's still right here: https://clojurescript.org/guides/quick-start Granted, it's for Windows only, even though I still have no clue why that would be a recommendation. In any case, classpaths are not set in stone and jars can easily omit versions. Given that there are at least two other solutions, I definitely prefer them. :)

thheller19:02:36

(slurp ( "META-INF/maven/org.clojure/clojurescript/pom.properties")) also works

👍 1