Very odd. It looks like the version of lein-figwheel is injecting this into the :cljsbuild config map in project.clj:
:target :bundle
:bundle-cmd {:none ["npx.cmd" "webpack" "--mode=development"]
:default ["npx.cmd" "webpack"]}
Which assumes the presence of node.js and webpack (wrongly IMO). The original figwheel template I started with did not do this. If I comment these out (either via ;; or using per-expression comments like #_ #_)
;;:target :bundle
#_ #_ :bundle-cmd {:none ["npx.cmd" "webpack" "--mode=development"]
:default ["npx.cmd" "webpack"]}
Then compiling is fine. Yet there’s another problem with the template:
It’s also compiling to a .js file that resources/public/index.html is not expecting. My project is called figtest
(identical setup as yours), and the index.html expects the compiled js to be at
<script src="js/compiled/figtest.js" type="text/javascript"></script>
Except the configuration the template sets up puts it at
:output-to "resources/public/js/compiled/out/figtest.js"
So when the page loads it fails to find the resource the index.html is requesting at public/js/figtest.js
One solution here is to make the project.clj conform to the index.html expectations (you could also go the other way and change index.html) by changing the :output-to key:
:output-to "resources/public/js/compiled/figtest.js"
With that everything loads and I get a cljs repl as expected. This is a notable contrast to my original experimentation with figwheel about 2 years back. My recent work has migrated to figweel-main which has an excellent tutorial, although figwheel is still viable. I think somebody jacked up the figwheel template along the way and maybe it worked on their setup, but it’s busted for others (you and me at least). Definitely worth filing a bug.
To recap, here is the cljsbuild settings I ended up with:
:cljsbuild {:builds
[{:id "dev"
:source-paths ["src"]
;; The presence of a :figwheel configuration here
;; will cause figwheel to inject the figwheel client
;; into your build
:figwheel {:on-jsload "figtest.core/on-js-reload"
;; :open-urls will pop open your application
;; in the default browser once Figwheel has
;; started and compiled your application.
;; Comment this out once it no longer serves you.
:open-urls ["http://localhost:3449/index.html"]}
:compiler {:main figtest.core
;;:target :bundle
:asset-path "js/compiled/out"
:output-to "resources/public/js/compiled/figtest.js"
:output-dir "resources/public/js/compiled/out"
#_#_ :bundle-cmd {:none ["npx.cmd" "webpack" "--mode=development"]
:default ["npx.cmd" "webpack"]}
:source-map-timestamp true
;; To console.log CLJS data-structures make sure you enable devtools in Chrome
;; https://github.com/binaryage/cljs-devtools
:preloads [devtools.preload]}}
;; This next build is a compressed minified build for
;; production. You can build this with:
;; lein cljsbuild once min
{:id "min"
:source-paths ["src"]
:compiler {:output-to "resources/public/js/compiled/figtest.js"
:main figtest.core
:optimizations :advanced
:pretty-print false}}]}
It looks like the “new” version of lein-figwheel (still old compared to figwheel-main) requires a +no-bundle option…ugh, a lot of old tutorials are wrong now. GitHub - bhauman/figwheel-template: A Leinigen template for figwheel
+no-bundle Generates a project without npm and webpack support.
So if you delete your project folder and start a new one, THIS time with:
lein new figwheel figtest -- +no-bundle
It will work out of the box (I just confirmed).