Hexo "Template render error" (EJS) in CI
Hexo renders theme layouts with EJS by default. When a layout reads a variable that is undefined for a page, or contains an EJS syntax error, generation throws "Template render error" naming the layout.
What this error means
hexo generate fails with "Template render error" and an EJS message such as "X is not defined" or "Could not find matching close tag", pointing at a theme layout.
hexo
FATAL Something's wrong. ...
Template render error: /themes/landscape/layout/post.ejs
ReferenceError: author is not definedCommon causes
A layout uses data missing for some pages
The EJS layout references page or config data that is absent for certain posts, throwing a ReferenceError during render.
An EJS syntax error in the theme
An unbalanced <% %> tag or stray delimiter in a layout makes EJS fail to compile.
How to fix it
Guard optional variables in the layout
Reference data defensively so a missing field does not throw.
themes/landscape/layout/post.ejs
<%- typeof author !== 'undefined' ? author : config.author %>Fix the EJS syntax the error names
- Open the layout file named in the error.
- Balance the EJS tags and correct the delimiter.
- Re-run
hexo generateto confirm it renders.
Terminal
npx hexo generateHow to prevent it
- Default optional fields in theme layouts.
- Keep config values the theme expects populated.
- Generate locally before pushing to catch layout errors.
Related guides
Hexo "Cannot find module" on generate in CIFix Hexo "Cannot find module 'hexo'" or a missing plugin/theme module in CI - a required package is not insta…
Eleventy "Template render error" on build in CIFix Eleventy "Template render error" in CI - a template threw while rendering, usually from an undefined vari…
Middleman ERb / template error on build in CIFix Middleman build failures from an ERb or template error in CI - `middleman build` raises a Ruby error (Nam…