Skip to content
Latchkey

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

  1. Read the function and arity the error names.
  2. Define it, or import/alias the module that provides it.
  3. Re-run mix compile to confirm it resolves.
lib/app/math.ex
defmodule App.Math do
  def add(a, b), do: a + b
end

Fix 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

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →