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/0Common 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
- Check the function definition to confirm how many arguments it takes.
- Adjust the call to that arity.
- 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-errorsin CI.
Related guides
Elixir MatchError failing tests in CIFix Elixir "(MatchError) no match of right hand side value" failing tests or builds in CI - a pattern match d…
Mix "Could not compile dependency" in CIFix Elixir Mix "Could not compile dependency :dep" in CI - a dependency failed to build due to missing tools,…
Scala "type mismatch" compile error in sbtFix Scala "type mismatch; found ... required ..." compile errors in sbt CI - wrong types, missing implicit co…