I'm using Leiningen 2.5.2 (Java 1.8.0_45-internal Open JDK 64-bit), and the reagent-template (i.e. lein new reagent foo
).
This runs okay with lein figwheel
as expected.
Next, the first thing I do is break out the "Views" functions into separate files and add them to the app namespace:
;; -------------------------
;; Views
(:require home-page)
(ns foo.core)
(defn home-page []
[:div [:h2 "Welcome to foo"]
[:div [:a {:href "#/about"} "go to about page"]]])
When I go to view the app in the browser (chromium or firefox), it gets stuck at "ClojureScript has not been compiled!" despite seemingly compiling successfully in the terminal. If I enter commands in the figwheel REPL, I see the green Clojure logo when it is working in the browser, so I know it's connected.
I had this working in a reagent app some months ago--what happened? How should I separate my view code? (A single file is unmanageable; that's a lot of Hiccup.)
If you really have only the line (:require home-page)
in core.cljs, this should be the culprit. The colon notation :require
is only valid inside a namespace declaration with ns
. Also, you declare the core namespace in the wrong file (home-page.cljs, not core.cljs). Take a look at this article on namespaces in Clojure for a thorough explanation.
You will want the following in core.cljs:
(ns foo.core
(:require [foo.home-page :as hp :refer [home-page]]))
.... more core.cljs code ...
and then simply in home-page.cljs:
(ns foo.home-page
(:require ....reagent namespaces as needed ....
(defn home-page [] ....