Skip to content
Latchkey

Middleman ERb / template error on build in CI

Middleman renders templates with ERb (and other engines). A Ruby error in a template - an undefined local, a bad helper call, or an ERb syntax error - makes middleman build raise and exit non-zero.

What this error means

middleman build fails with a Ruby error such as "NameError: undefined local variable or method" or "SyntaxError", naming the source template.

middleman
== Request: /index.html
NameError: undefined local variable or method `current_page' for ...
  source/index.html.erb:3:in `...'
The Middleman is terminating due to an error

Common causes

A template calls an undefined helper or local

The ERb references a variable or helper that is not in scope during the build (for example a server-only helper).

An ERb or data error

A syntax error in the ERb, or reading a key absent from a data file, raises during render.

How to fix it

Guard or define the template reference

  1. Open the template at the reported line.
  2. Define the missing helper or guard the optional value.
  3. Re-run middleman build.
source/index.html.erb
<%= data.site && data.site.title %>

Install gems before building

Ensure helpers from gems are available by installing with the committed lockfile first.

.github/workflows/ci.yml
- run: bundle install
- run: bundle exec middleman build

How to prevent it

  • Guard optional data and helpers in templates.
  • Install gems with the lockfile before building.
  • Build locally to catch ERb errors before CI.

Related guides

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