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.
== 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 errorCommon 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
- Open the template at the reported line.
- Define the missing helper or guard the optional value.
- Re-run
middleman build.
<%= data.site && data.site.title %>Install gems before building
Ensure helpers from gems are available by installing with the committed lockfile first.
- run: bundle install
- run: bundle exec middleman buildHow 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.