Skip to content
Latchkey

Elixir "** (CompileError) undefined function" in CI

Elixir resolves many calls at compile time. A CompileError for an undefined function means the name is not in scope: not imported, not aliased, or belonging to a module that did not compile or is not a dependency.

What this error means

mix compile fails with "** (CompileError) lib/....ex:NN: undefined function foo/1 (expected Module to define such a function)".

** (CompileError)
** (CompileError) lib/my_app/mailer.ex:12: undefined function deliver_later/1
    (expected MyApp.Mailer to define such a function or for it to be imported,
     but none are available)

Common causes

Missing import, alias, or require

The function exists elsewhere but is not brought into scope, so the compiler treats the bare call as undefined.

The providing module or dep did not compile in CI

A dependency present locally but not fetched in CI (or a module skipped by a compile-env difference) leaves the function undefined.

How to fix it

Bring the function into scope

  1. Add the correct alias, import, or module-qualified call.
  2. Confirm the module that defines it compiles (check earlier errors).
  3. Recompile to confirm the call resolves.
lib/my_app/mailer.ex
defmodule MyApp.Mailer do
  use Swoosh.Mailer, otp_app: :my_app
end

# call it qualified
MyApp.Mailer.deliver(email)

Ensure deps are fetched before compile

A function from a Hex package is undefined if the dep was never fetched in the job.

Terminal
mix deps.get
mix compile

How to prevent it

  • Alias/import modules explicitly rather than relying on scope.
  • Fetch deps before compiling in CI.
  • Fix the first compile error first; later ones often cascade.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →