Howdy! I’ve been using LiveBook to use as a playground/teaching tool for a small app I’m developing.
I started running into an issue where, when using LiveBook, I would get a “Jason Encoder not implemented” error for a struct that is in my project, even though I had @derive Jason.Encoder
right on top of the defstruct
macro in the struct’s module.
The only thing I could do to fix the error was to add consolidate_protocols: false
in the Mix.install
function that I run as part of my LiveBook initialization block.
The offending struct was not defined in LiveBook–it was defined in the project I’m adding to Livebook as a dependency.
I have never fully groked what “protocol consolidation” is (and I wasn’t able to fully understand the docs), but I had sort of a nebulous understanding that consolidate_protocols: false
was required when structs were defined dynamically during runtime.
However, in this case that’s not true–my offending struct was defined in my project, so it seems like it’s something to do with LiveBook?
So two questions:
- Is this something LiveBook specific? And if so, what?
- Any tips for understanding what
consolidate_protocols: false
actually does?
FWIW, this is what my LiveBook initialization block looks like:
my_app_root = Path.join(__DIR__, "..")
Mix.install(
[
{:salesbot, path: my_app_root, env: :dev}, <-- This is my app
{:kino, "~> 0.10.0"},
{:kino_db, "~> 0.2.1"},
{:postgrex, "~> 0.16.3"},
{:kino_vega_lite, "~> 0.1.7"}
],
config_path: Path.join(my_app_root, "config/config.exs"),
lockfile: Path.join(my_app_root, "mix.lock"),
consolidate_protocols: false <-- Without this line I get an error
)