This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-10-06
Channels
- # beginners (32)
- # boot (17)
- # cider (4)
- # clara (112)
- # cljs-dev (3)
- # cljsjs (2)
- # clojure (222)
- # clojure-germany (3)
- # clojure-greece (1)
- # clojure-italy (4)
- # clojure-losangeles (4)
- # clojure-russia (46)
- # clojure-spec (24)
- # clojure-uk (71)
- # clojurescript (78)
- # community-development (5)
- # component (88)
- # cursive (6)
- # datomic (7)
- # duct (5)
- # figwheel (2)
- # fulcro (21)
- # graphql (22)
- # leiningen (3)
- # luminus (9)
- # off-topic (1)
- # om (16)
- # onyx (46)
- # portkey (30)
- # re-frame (47)
- # reagent (5)
- # remote-jobs (1)
- # ring (12)
- # ring-swagger (13)
- # rum (1)
- # shadow-cljs (81)
- # spacemacs (1)
- # specter (33)
- # sql (2)
- # test-check (2)
- # vim (16)
- # yada (11)
Didn't know that there was a component channel 🙂. I've been loving the idea of component, and structured all my projects with it. However, the namespace refresh seems quite unstable in my projects. Quite frequently it just breaks because it's unable to find some (random?) namespace. Does anyone here have similar problems? How did you solve them?
e.g. cyclical dependencies of one k ind or another, missing dependencies, using import and java constructors for records instead of require and the factory functions
@hiredman Interesting! Any idea how to debug such problems?
I would start by looking at the namespace named in the error message, and then trying to load that namespace with require in otherwise clean repl
@hiredman Starting a new repl 🙂. Hmm..
it is very possible you'll find that the code on disk isn't valid and won't compile in a fresh repl, and there was some left over state that was allowing it to compile for whatever reason
the refresh error messages tend to just point at the namespace that is a problem, without telling you want the problem is, where as if you manually load the code you will get a real error message that tells you what the error is
I'm quite sure the code in the namespaces is working correctly. I think it's probably more like a cyclical dependency or something.
I've started a new REPL repl and required the namespace, which worked, than loaded everything and than required with the :reload flag and works too.
when I refresh it doesn't... But with manually requiring with reload works
if its a circular dependency in general, if you rare requiring via the ns form, you will get an error for circular deps, if you are doing something more complicated then you have taken your fate in to your own hands
What is "more complicated"? I only require via the ns
form but never seen a warning
Only records, as components. But I don't use them directly, only the helper function which calls map->Web
for example.
Hmmm. So, I've been trying to remove the require in the ns
form of the function which cannot be found. It fixes that specific error-case, but than another namespace doesn't load. Have done this 8 times now and doesn't seem to stop
you may be walking back through a cycle, the require code tries to detect those and throw an error, but I dunno, there may be something that circumvents that
I'm just using a simple leiningen setup, no special build steps. Well, refresh isn't able to find namespaces, so I don't think it can find all the source code...?
Not sure 😛
@stex any chance your namespace is using a namespace that it doesn’t require, but is available because another namespace required it?
this could easily go bad when refreshing (and is a bad idea anyway)
@noisesmith Sounds plausable. I'll start grepping the source files
also, what is the specific error message you are seeing for the missing namespace?
@noisesmith I cannot find any usages of a namespace without requiring it first. Only clojure.string and http://clojure.java.io, but that is fine, right?
no, but that isn’t your problem
clojure.string isn’t loaded by default - so it can work to use it without a require in dev, but break when running from a jar
http://clojure.java.io is used by clojure itself in bootstrapping, so that won’t break the same way (currently) but there’s no promise that implicitly relying on it being present won’t break in the future
considering that the fix is just one line in a require form, it’s better to add it for consistency’s sake anyway
so you are using slamhound to invoke c.t.n/reload ? if not, it could be that something slamhound is trying to do gets broken by the refresh
@noisesmith Yep, I've replaced both occurrences right away 👍. Doesn't solve reset though.
what’s the slamhound process doing exactly?
iirc slamhound messes with your namespaces, and I could see it going bonkers if someone deletes a namespace (and that’s something refresh does in order to get a clean state)
Hmm.. Seems like slamhound is something of cljr-refactor in cider... Let's try a simple lein repl
session...
OK - if you aren’t explicitly using slamhound to drive your refresh, I bet refresh and slamhound are getting in a spat 😄
I don't know what slamhound is actually, I'm just using cljr-refactor in cider 😛
Well, lein repl
gives the same issue, no stacktrace though
yeah, clj-refactor is built on slamhound iirc
(pst) will show you the stack trace
wouldn’t lein repl still pull in cider if you have it set up in your profiles.clj?
or is the new cider injecting the plugin manually?
Cider is injecting the manually
:error-while-loading project.erp.agp.client
CompilerException java.lang.Exception: namespace 'project.erp.agp.parsers' not found, compiling:(project/erp/agp/client.clj:1:1)
user=> (pst)
CompilerException java.lang.Exception: namespace 'project.erp.agp.parsers' not found, compiling:(project/erp/agp/client.clj:1:1)
clojure.core/throw-if (core.clj:5656)
clojure.core/load-lib (core.clj:5742)
clojure.core/load-lib (core.clj:5717)
clojure.core/apply (core.clj:648)
clojure.core/load-libs (core.clj:5774)
clojure.core/load-libs (core.clj:5758)
clojure.core/apply (core.clj:648)
clojure.core/require (core.clj:5796)
clojure.core/require (core.clj:5796)
project.erp.agp.client/eval28368/loading--5569--auto----28369 (client.clj:1)
project.erp.agp.client/eval28368 (client.clj:1)
project.erp.agp.client/eval28368 (client.clj:1)
Caused by:
Exception namespace 'project.erp.agp.parsers' not found
nil
When I require them manually (directly after the other output) it just works...
user=> (require 'project.erp.agp.parsers)
nil
user=> (require 'project.erp.agp.parsers :reload)
nil
@stex do you have a user.clj in that project by any chance (eg. it might have been created by a template)
Yep, i do use user.clj
There I load the (reset)
functions and some other functions
@stex I just found this > Adding a :main to your project.clj will enable AOT compilation and thus break clojure.tools.namespace/refresh. I worked around this by declaring my main in the :uberjar profile.
Yep, I've seen that. I've only added the main to the :uberjar profile.
:thumbsup:
so you have no main or aot in other profiles?
Nop, just in the uberjar (just checked it)
Is it fine to load setup the reset function in the user.clj
?
sometimes there are shenanigans going on with user.clj, in particular if it helpfully preloads some of your namespaces, so it’s worth double checking it’s not trying to be too clever
@stex the other gotcha with aot / refresh is that even if you only have aot / main set for uberjar, if you run a repl after uberjar without running clean first, you’ll get that same error
😮. For some reason the error disapears when I move the code from the user namespace to a new dev namespace
haha, sweet
Oke, just to be sure it isn't the lein clean + uberjar thing I'll revert 🙂
Sweet, but weird 😄
Curious why this works
do weird things, get weird results, some templates (eg. luminus) put sketchy stuff in user.clj
I don't like templates 🙂. Created user myself and it's super minimal
oh, OK - well regardless of why I helped, glad I could help haha
(ns user
(:import java.lang.Runtime)
(:require [figwheel-sidecar.system :as sys]
[com.stuartsierra.component.repl :refer [set-init system start stop reset]]
[com.stuartsierra.component :as component]
[project.utils.env :refer [env]]
[project.components.system :refer [create-system-map]]))
(defrecord ScssCompiler []
component/Lifecycle
(start [this]
(if-not (:process this)
(do
(println "Starting SCSS watch process...")
(assoc this :process
(.exec (Runtime/getRuntime) "bin/watch-sass")))
this))
(stop [this]
(when-let [process (:process this)]
(println "Stopping SCSS watch process...")
(.destroy process))
this))
(defn cljs []
(sys/cljs-repl (:figwheel-system system)))
(defn dev-system [_]
(assoc (create-system-map env)
:scss-compiler (->ScssCompiler)
:figwheel-system (sys/figwheel-system
(assoc-in (sys/fetch-config) [:data :build-ids] ["dev" "figwheel-test"]))
:css-watcher (component/using
(sys/css-watcher {:watch-paths ["resources/public/css"]})
{:figwheel-server :figwheel-system})))
(set-init dev-system)
That's my user.clj, Do you find anything weird?
Oh, oke! It works now also when I lein clean
and keep everything in the user.clj
aha, so it was a caching issue
that makes a lot more sense, that user.clj looks fine
@stex instead of remembering to run lein clean, you could make sure the target-path of uberjar isn’t in the repl’s classpath
How do you do that specifically?
by eg. setting a custom compile-path or target-path (forget the config name) under the uberjar profile
lein help sample
should reference it somewhere
Thanks man!!
Super happy I know it's a caching problem. I've been having these weird issues in all my projects for months now and was really really fed up with it
@stex I’ve hit enough random leiningen caching problems (and wasted enough time on them) that I now double check if lein clean
fixes my issue before even thinking about the actual bug if I have any problem with finding namespaces or classes
Haha, will remember that for the next time 😉
but it’s so automatic that I sometimes forget to recommend it for others
Could have saved me a lot of time
Yep, i've tried a uberjar, ran reset and the issue reappeared. Fixed by lein clean
nice 🙂
It's late here already, going to bed. Thanks @noisesmith and @hiredman!! Much appreciated.