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 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.
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 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.
Related guides
Bridgetown "could not be built" Liquid error in CIFix Bridgetown "Liquid error" / page "could not be built" during `bridgetown deploy` in CI - a Liquid templat…
Zola "Couldn't find template" in CIFix Zola "Reason: Couldn't find template X" in CI - a page or section asks for a template file that does not…
Hexo "Template render error" (EJS) in CIFix Hexo "Template render error" from an EJS theme template in CI - a theme layout references an undefined va…