Skip to content
Latchkey

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 defined

Common 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

  1. Open the layout file named in the error.
  2. Balance the EJS tags and correct the delimiter.
  3. Re-run hexo generate to confirm it renders.
Terminal
npx hexo generate

How 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

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