clojure.tools/namespace refresh fails with "No namespace: foo"

Viewed 1080

I'm using tools.namespace to provide smart reloading of namespaces on the REPL. However, when calling refresh or refresh-all, it throws an error.

user=> (require '[clojure.tools.namespace.repl :as tn])
user=> (tn/refresh)
:reloading (ep31.common ep31.routes ep31.config ep31.application user ep31.common-test ep31.example-test)
:error-while-loading user

java.lang.Exception: No namespace: ep31.config, compiling:(user.clj:1:1)

And it seems to end up in this weird state where (require ep31.config) works without an error, but afterwards the namespace isn't actually defined.

2 Answers

I learned this the hard way, documentation for :target-path says (https://github.com/technomancy/leiningen/blob/master/sample.project.clj#L309-L313):

;; All generated files will be placed in :target-path. In order to avoid
;; cross-profile contamination (for instance, uberjar classes interfering
;; with development), it's recommended to include %s in in your custom
;; :target-path, which will splice in names of the currently active profiles.
:target-path "target/%s/"

I guess there has to be legacy reasons that :target-path "target/%s/" isn't the default.

Related