Elixir "protocol has not been consolidated" warning in CI
Elixir consolidates protocols at compile time for speed. A "has not been consolidated" warning (or a Protocol.UndefinedError) in CI usually means a stale _build was restored and a newly added implementation was not re-consolidated.
What this error means
CI logs "warning: the protocol Enumerable has not been consolidated" or a test fails with "** (Protocol.UndefinedError) protocol X not implemented for ...".
warning: the protocol Jason.Encoder has not been consolidated
** (Protocol.UndefinedError) protocol Jason.Encoder not implemented for %MyApp.Money{}Common causes
Stale consolidated protocols in a restored _build
A cached _build holds consolidated beams from before your new implementation existed, so the impl is not registered.
Consolidation disabled or partial in the compile step
A compile that skipped consolidation, or mixed environments, leaves protocols un-consolidated at runtime.
How to fix it
Force a clean compile so protocols re-consolidate
- Clear stale build artifacts and recompile.
- Ensure the cache key changes when Elixir/OTP or deps change.
- Re-run so the new implementation is consolidated.
mix clean
mix compileKey the _build cache correctly
Include OTP/Elixir versions and mix.lock in the _build cache key so a fresh consolidation happens after relevant changes.
key: build-${{ runner.os }}-otp${{ steps.beam.outputs.otp-version }}-${{ hashFiles('**/mix.lock') }}How to prevent it
- Include toolchain and lock hashes in the _build cache key.
- Recompile cleanly when protocol implementations change.
- Avoid sharing _build caches across different environments.