Closed raxod502 closed 7 years ago
The classpath is different when you use lein figwheel
and lein repl
. The figwheel plugin adds the all the ClojureScript paths ["src/cljs" "src/cljc" "env/dev/cljs"]
to the classpath. And in order for the compiler to find the source code it searches the classpath. In many cases things will still work without setting the classpath correctly.
You will have to add ["src/cljs" "src/cljc" "env/dev/cljs"]
the top level :source-paths
in your project.clj to get the behavior you want.
When I use
require
in the figwheel-sidecar REPL, I get a spurious error message.Steps to reproduce:
``` temp % lein new reagent funk Generating fresh 'lein new' Reagent project. temp % cd funk funk % lein repl 2017-07-23 13:03:18.066:INFO::main: Logging initialized @17880ms nREPL server started on port 63811 on host 127.0.0.1 - nrepl://127.0.0.1:63811 REPL-y 0.3.7, nREPL 0.2.13 Clojure 1.8.0 Java HotSpot(TM) 64-Bit Server VM 1.8.0_112-b16 Docs: (doc function-name-here) (find-doc "part-of-name-here") Source: (source function-name-here) Javadoc: (javadoc java-object-or-class-here) Exit: Control+D or (exit) or (quit) Results: Stored in vars *1, *2, *3, an exception in *e funk.repl=> (use 'figwheel-sidecar.repl-api) nil funk.repl=> (start-figwheel!) Figwheel: Starting server at http://0.0.0.0:3449 Figwheel: Watching build - app Figwheel: Cleaning build - app Compiling "target/cljsbuild/public/js/app.js" from ["src/cljs" "src/cljc" "env/dev/cljs"]... Successfully compiled "target/cljsbuild/public/js/app.js" in 7.623 seconds. Figwheel: Starting CSS Watcher for paths ["resources/public/css"] Figwheel: Starting nREPL server on port: 7002 nil funk.repl=> (cljs-repl) Launching ClojureScript REPL for build: app Figwheel Controls: (stop-autobuild) ;; stops Figwheel autobuilder (start-autobuild [id ...]) ;; starts autobuilder focused on optional ids (switch-to-build id ...) ;; switches autobuilder to different build (reset-autobuild) ;; stops, cleans, and starts autobuilder (reload-config) ;; reloads build config and resets autobuild (build-once [id ...]) ;; builds source one time (clean-builds [id ..]) ;; deletes compiled cljs target files (print-config [id ...]) ;; prints out build configurations (fig-status) ;; displays current state of system (figwheel.client/set-autoload false) ;; will turn autoloading off (figwheel.client/set-repl-pprint false) ;; will turn pretty printing off Switch REPL build focus: :cljs/quit ;; allows you to switch REPL to another build Docs: (doc function-name-here) Exit: Control+C or :cljs/quit Results: Stored in vars *1, *2, *3, *e holds last exception object Prompt will show when Figwheel connects to your application To quit, type: :cljs/quit nil cljs.user=> (require 'funk.core) ---- Exception ---- Namespace funk.core does not exist ---- Exception Stack Trace ---- java.lang.IllegalArgumentException: Namespace funk.core does not exist at cljs.closure$source_for_namespace.invokeStatic (closure.clj:707) cljs.closure$source_for_namespace.invoke (closure.clj:680) cljs.repl$load_namespace.invokeStatic (repl.cljc:195) cljs.repl$load_namespace.invoke (repl.cljc:179) cljs.repl$load_dependencies.invokeStatic (repl.cljc:220) cljs.repl$load_dependencies.invoke (repl.cljc:216) cljs.repl$evaluate_form.invokeStatic (repl.cljc:489) cljs.repl$evaluate_form.invoke (repl.cljc:443) cljs.repl$eval_cljs.invokeStatic (repl.cljc:602) cljs.repl$eval_cljs.invoke (repl.cljc:595) clojure.lang.Var.invoke (Var.java:394) figwheel_sidecar.repl$catch_warnings_and_exceptions_eval_cljs.invokeStatic (repl.clj:253) figwheel_sidecar.repl$catch_warnings_and_exceptions_eval_cljs.invoke (repl.clj:245) clojure.lang.Var.invoke (Var.java:394) cljs.repl$repl_STAR_$read_eval_print__20201.invoke (repl.cljc:862) cljs.repl$repl_STAR_$fn__20207$fn__20216.invoke (repl.cljc:903) cljs.repl$repl_STAR_$fn__20207.invoke (repl.cljc:902) cljs.compiler$with_core_cljs.invokeStatic (compiler.cljc:1206) cljs.compiler$with_core_cljs.invoke (compiler.cljc:1195) cljs.repl$repl_STAR_.invokeStatic (repl.cljc:864) cljs.repl$repl_STAR_.invoke (repl.cljc:737) cemerick.piggieback$run_cljs_repl.invokeStatic (piggieback.clj:169) cemerick.piggieback$run_cljs_repl.invoke (piggieback.clj:155) clojure.lang.AFn.applyToHelper (AFn.java:171) clojure.lang.AFn.applyTo (AFn.java:144) clojure.core$apply.invokeStatic (core.clj:650) clojure.core$apply.invoke (core.clj:641) cemerick.piggieback$evaluate.invokeStatic (piggieback.clj:259) cemerick.piggieback$evaluate.invoke (piggieback.clj:255) clojure.lang.Var.invoke (Var.java:379) cemerick.piggieback$wrap_cljs_repl$fn__31336$fn__31338$fn__31339.invoke (piggieback.clj:291) cemerick.piggieback$enqueue$fn__31322.invoke (piggieback.clj:247) clojure.tools.nrepl.middleware.interruptible_eval$run_next$fn__27793.invoke (interruptible_eval.clj:190) clojure.lang.AFn.run (AFn.java:22) java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1142) java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:617) java.lang.Thread.run (Thread.java:745) nil cljs.user=> funk.core #js {:home_page #object[funk$core$home_page "function funk$core$home_page(){ return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"div","div",1057191632),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"h2","h2",-372662728),"Welcome to funk"], null),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"div","div",1057191632),new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"a","a",-2123407586),new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"href","href",-793805698),"/about"], null),"go to about page"], null)], null)], null); }"], :about_page #object[funk$core$about_page "function funk$core$about_page(){ return new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"div","div",1057191632),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"h2","h2",-372662728),"About funk"], null),new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"div","div",1057191632),new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"a","a",-2123407586),new cljs.core.PersistentArrayMap(null, 1, [new cljs.core.Keyword(null,"href","href",-793805698),"/"], null),"go to the home page"], null)], null)], null); }"], :page #, :current_page #object[funk$core$current_page "function funk$core$current_page(){
return new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Keyword(null,"div","div",1057191632),new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [cljs.core.deref.call(null,funk.core.page)], null)], null);
}"], :mount_root #object[funk$core$mount_root "function funk$core$mount_root(){
return reagent.core.render.call(null,new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [funk.core.current_page], null),document.getElementById("app"));
}"], :init_BANG_ #object[funk$core$init_BANG_ "function funk$core$init_BANG_(){
accountant.core.configure_navigation_BANG_.call(null,new cljs.core.PersistentArrayMap(null, 2, [new cljs.core.Keyword(null,"nav-handler","nav-handler",2039495484),(function (path){
return secretary.core.dispatch_BANG_.call(null,path);
}),new cljs.core.Keyword(null,"path-exists?","path-exists?",1473384514),(function (path){
return secretary.core.locate_route.call(null,path);
})], null));
accountant.core.dispatch_current_BANG_.call(null);
return funk.core.mount_root.call(null);
}"]}
cljs.user=>
```
Note in particular that the namespace is in fact defined. Thus the error is spurious(?).
See also https://github.com/clojure-emacs/cider/issues/2028.
The error does not happen with
lein figwheel
:``` temp % lein new reagent funk Generating fresh 'lein new' Reagent project. temp % cd funk funk % lein figwheel Figwheel: Cutting some fruit, just a sec ... Figwheel: Validating the configuration found in project.clj Figwheel: Configuration Valid :) Figwheel: Starting server at http://0.0.0.0:3449 Figwheel: Watching build - app Figwheel: Cleaning build - app Compiling "target/cljsbuild/public/js/app.js" from ["src/cljs" "src/cljc" "env/dev/cljs"]... Successfully compiled "target/cljsbuild/public/js/app.js" in 9.206 seconds. Figwheel: Starting CSS Watcher for paths ["resources/public/css"] Figwheel: Starting nREPL server on port: 7002 Launching ClojureScript REPL for build: app Figwheel Controls: (stop-autobuild) ;; stops Figwheel autobuilder (start-autobuild [id ...]) ;; starts autobuilder focused on optional ids (switch-to-build id ...) ;; switches autobuilder to different build (reset-autobuild) ;; stops, cleans, and starts autobuilder (reload-config) ;; reloads build config and resets autobuild (build-once [id ...]) ;; builds source one time (clean-builds [id ..]) ;; deletes compiled cljs target files (print-config [id ...]) ;; prints out build configurations (fig-status) ;; displays current state of system (figwheel.client/set-autoload false) ;; will turn autoloading off (figwheel.client/set-repl-pprint false) ;; will turn pretty printing off Switch REPL build focus: :cljs/quit ;; allows you to switch REPL to another build Docs: (doc function-name-here) Exit: Control+C or :cljs/quit Results: Stored in vars *1, *2, *3, *e holds last exception object Prompt will show when Figwheel connects to your application To quit, type: :cljs/quit app:cljs.user=> (require 'funk.core) nil app:cljs.user=> ```
Also, if I use
cljs.core/require
instead ofrequire
, then there's no error. What??