Skip to content
Latchkey

rebar3 "function undefined" / "unbound variable" compile error in CI

rebar3 invoked the Erlang compiler and it rejected a reference. "function X/N undefined" means no such function with that arity is in scope; "variable Y is unbound" means a variable is used before it is bound.

What this error means

rebar3 compile fails after "Compiling app" with "function X/N undefined" or "variable Y is unbound", citing the module and line.

rebar3
===> Compiling myapp
src/myapp_server.erl:14: function start_lnk/0 undefined
src/myapp_server.erl:22: variable 'Reply' is unbound

Common causes

A misspelled or unexported function

The call names a function with the wrong arity, a typo, or one not exported from its module, so it is undefined at the call site.

A variable used before binding

Erlang variables are single-assignment; referencing a name not yet bound in this clause (or a typo in the name) makes it unbound.

How to fix it

Fix the name, arity, or export

  1. Correct the function name and arity to match its definition.
  2. Add it to the module's -export([...]). list if it is called from outside.
  3. Re-run rebar3 compile.
src/myapp_server.erl
-export([start_link/0]).

Bind the variable before use

Ensure the variable is bound earlier in the same clause and spelled identically, since Erlang variables are case-sensitive and single-assignment.

src/myapp_server.erl
Reply = handle(Request),
{reply, Reply, State}.

How to prevent it

  • Export every function called from another module.
  • Match function arity exactly at call sites.
  • Compile locally before pushing; these errors are deterministic.

Related guides

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