fireproofsocks
Is it possible to use a dependency's structs inside of config?
I am bumping into some limits of my own understanding when it comes to application configuration. Specifically, I was wanting to reference a dependency’s structs inside my app’s configuration. I’m getting errors like this:
** (CompileError) config/components.exs:27: SomeDep.__struct__/1 is undefined, cannot expand struct
Is there a way to ensure that the dependency is compiled and that its structs are available when my app is being compiled? Or am I putting the carriage before the horse?
Thanks for any clarifications!
Most Liked
fireproofsocks
Ah… from the docs:
config/config.exs- this file is read at build time, before we compile our application and before we even load our dependencies. This means we can’t access the code in our application nor in our dependencies. However, it means we can control how they are compiled
I guess I either move the structs over to the runtime.exs or I make the config work without structs.
fireproofsocks
The only reason that the compile-time config would be nice in this case is for documentation purposes: I can reference the config from inside a @moduledoc and generate accurate information about how the app is set up (e.g. via a Mermaid chart). For a complex app, that starts to feel like more than a “nice-to-have”, but technically, the app is totally functional if that info is supplied at run-time.
For a quick fix (albeit ugly), I can reference the structs via apply/3 so they don’t cause problems during build-time.
A better option might be to figure out a mix task/alias that would generate the necessary charts at runtime and include these pages linked up to the other ExDoc outputs.







