Elixir "(CompileError) undefined function" in CI
The Elixir compiler found a call to a function that is not defined or imported with that name and arity. It raises CompileError at compile time, naming the function and arity it could not resolve.
What this error means
mix compile fails with "** (CompileError) lib/file.ex:N: undefined function foo/1" or "undefined function ... (expected ... to define such a function)".
elixir
** (CompileError) lib/app/math.ex:5: undefined function add/2
(module App.Math is not available or is yet to be defined)
(elixir 1.16.2) ...Common causes
The function is not defined or imported
A call uses a name and arity that no def provides and no import/alias brings into scope.
A typo in the name or arity
The function exists with a different arity or spelling, so the exact name/N is undefined.
How to fix it
Define or import the function
- Read the function and arity the error names.
- Define it, or
import/aliasthe module that provides it. - Re-run
mix compileto confirm it resolves.
lib/app/math.ex
defmodule App.Math do
def add(a, b), do: a + b
endFix the name or arity at the call site
When the function exists with a different signature, correct the call to match the defined name/arity.
How to prevent it
- Match function name and arity exactly at call sites.
- Import or alias modules whose functions you call unqualified.
- Compile locally so undefined calls surface before CI.
Related guides
Elixir "(Mix) Could not compile dependency" in CIFix Elixir "** (Mix) Could not compile dependency :X" in CI - a dependency failed to compile, often a missing…
Elixir "Compilation failed ... --warnings-as-errors" in CIFix Elixir "Compilation failed due to warnings while using the --warnings-as-errors option" in CI - mix compi…
Elixir "(Mix) The task X could not be found" in CIFix Elixir "** (Mix) The task \"X\" could not be found" in CI - Mix has no task by that name because the prov…