bhauman / devcards

Devcards aims to provide a visual REPL experience for ClojureScript
1.53k stars 116 forks source link

Lots of Undeclared Var warnings #99

Closed magnars closed 5 years ago

magnars commented 8 years ago

Starting figwheel with devcards, I get lots of these:

WARNING: Use of undeclared Var devcards.core/register-card at line 81 src/link_app/components/header.cljs
WARNING: Use of undeclared Var devcards.core/card-base at line 81 src/link_app/components/header.cljs

One such pair per defcard invocation.

I use it like this:

(:require-macros [devcards.core :as dc :refer [defcard]])
(defcard foo
  (FooComponent {:title "foo"}))

This happens with both [devcards "0.2.1-6"] and [devcards "0.2.0-8"]. ClojureScript version 1.7.228

Any ideas?

magnars commented 8 years ago

Yep, figured it out. I had omitted the plain :require for devcards.

magnars commented 8 years ago

Could possibly change the readme to use [devcards.core :refer-macros [defcard]] to avoid the double require? :)

bhauman commented 8 years ago

Hmmm this is all dependent on the environment. I did a lot of work to make sure that devcards gets completely excluded from the application when it's not needed. But this is all a bit tenuous.

I'm going to revisit this soon because nobody is really using devcards this way.

Are you using :devcards true?

magnars commented 8 years ago

Yeah, it worked just as expected when I included (:require [devcards.core]) along with the :require-macros. It also worked when I simplified it down to (:require [devcards.core :refer-macros [defcard]]) to avoid having to have statements declaring devcards in both :require and :require-macros. Which was where I had blundered with copy-paste earlier. :stuck_out_tongue:

We are currently using devcards inline with the production code, but there's no problem moving them out to a devcards-folder. It is nice having some examples straight there in the code tho. :smile:

Our config looks like this:

{:id "devcards"
 :source-paths ["src"]
 :figwheel {:devcards true}
 :compiler {:main "link-app.director"
            :asset-path "js/compiled/devcards-out"
            :output-to "resources/public/js/compiled/link-app-devcards.js"
            :output-dir "resources/public/js/compiled/devcards-out"
            :source-map-timestamp true}}
bhauman commented 8 years ago

Yeah when you require 'devcards.core and not just the macros you will get a large compiled codebase increase.
Just requiring the macros ensures that there is no devcards output in the final compiled output.
The warnings may happen initially but should maybe go away on subsequent compiles.

bhauman commented 8 years ago

Again I will have to look at this.

magnars commented 8 years ago

Aha, I see! That makes sense.

Yeah, the warnings are only on the first load of devcards. It gets really spammy when starting the repl tho, and I'm trying to show the other developers here the wonderful world of figwheel+devcards+cljs - I didn't want their first impression to be 60 error messages. :smile:

Thanks for looking into it!

kommen commented 6 years ago

As we ran into this issue, we used this workaround: Have a namespace myproject.devcards, which all namespaces with inline defcards require in addition to the require-macros. This myproject.devcards is empty the classpaths for all builds, except for the devcards build, where we include a version of it where it :requires devcards.core.

This solves the warnings and lets us have the defcards inline with the code while not shipping devcards in our production builds.

bhauman commented 5 years ago

That's really the only solution that makes sense.