Skip to content
Latchkey

Elixir CompileError "undefined function" in CI

The Elixir compiler reached a call to a function it cannot resolve. The function is not defined, not imported, or called with the wrong arity.

What this error means

Compilation fails with (CompileError) undefined function foo/1, pointing at the call site. It is deterministic and reproduces on every build.

mix
** (CompileError) lib/app.ex:9: undefined function foo/1
    (elixir 1.16.0) expanding macro: ...
    lib/app.ex:9: App.run/0

Common causes

Function not imported or aliased

Calling a function from another module without import, alias, or a full module prefix leaves it undefined.

Wrong arity

The function exists with a different number of arguments, so foo/1 is undefined while foo/2 exists.

Macro used before it is required

A macro is invoked without require-ing its module, so the compiler does not see it.

How to fix it

Import or fully qualify the call

app.ex
import MyApp.Helpers, only: [foo: 1]
# or
MyApp.Helpers.foo(arg)

Match the correct arity

  1. Check the function definition to confirm how many arguments it takes.
  2. Adjust the call to that arity.
  3. Remember default args change the arities a function exports.

require modules that export macros

Add require ModuleName before using its macros.

How to prevent it

  • Let the compiler warnings flag undefined calls early.
  • Keep imports and aliases tidy.
  • Run mix compile --warnings-as-errors in CI.

Related guides

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