gohugoio/hugo · critical

template %s not parsed

Error message

template %s not parsed

What it means

Internal panic in Hugo's template transformer (applyTemplateTransformers in tpl/tplimpl/templatetransform.go). Before applying node transformations, Hugo fetches the parse tree of the template via getParseTree; a nil tree means the template object was never parsed by text/template or html/template, which should be impossible in a healthy build, so Hugo panics rather than continuing with a corrupt template store.

Source

Thrown at tpl/tplimpl/templatetransform.go:84

		templateNotFound: make(map[string]bool),
		deferNodes:       make(map[string]*parse.ListNode),
	}
}

func applyTemplateTransformers(
	t *TemplInfo,
	store *TemplateStore,
	lookupFn func(name string, in *TemplInfo) *TemplInfo,
) (*templateTransformContext, error) {
	if t == nil {
		return nil, errors.New("expected template, but none provided")
	}

	c := newTemplateTransformContext(t, store, lookupFn)
	c.t.ParseInfo = defaultParseInfo
	tree := getParseTree(t.Template)
	if tree == nil {
		panic(fmt.Errorf("template %s not parsed", t))
	}

	if err := c.applyTransformationsAndSetReturnWrapper(tree); err != nil {
		return c, fmt.Errorf("failed to transform template %q: %w", t.Name(), err)
	}

	return c, c.err
}

func getParseTree(templ tpl.Template) *parse.Tree {
	if text, ok := templ.(*texttemplate.Template); ok {
		return text.Tree
	}
	return templ.(*htmltemplate.Template).Tree
}

const (
	// We parse this template and modify the nodes in order to assign

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Run 'hugo --logLevel debug' to identify which template triggers the panic, and check that template file for syntax that fails to parse cleanly.
  2. Upgrade to the latest Hugo release — panics in the template transformer are treated as bugs and fixed quickly.
  3. Bisect by removing recently added/changed templates (especially inline templates defined with {{ define }}) to find the offender.
  4. If reproducible on latest Hugo, file an issue at github.com/gohugoio/hugo with a minimal reproducer, as this indicates an internal bug.
Defensive patterns

Strategy: validation

Validate before calling

// Ensure the template exists before referencing it
{{ if templates.Exists "partials/mypartial.html" }}
  {{ partial "mypartial.html" . }}
{{ end }}

Prevention

When it happens

Trigger: A *TemplInfo reaches applyTemplateTransformers with a Template whose Tree field is nil — i.e. a template registered in the TemplateStore without going through parsing. Normally only reachable via a Hugo bug, a corrupt module/theme template load, or custom code embedding hugolib that inserts unparsed templates.

Common situations: Users hit this as a panic stack trace during 'hugo' or 'hugo server', typically after a Hugo version upgrade that changed the template store, or with unusual template setups (inline partials, template redefinition across theme components) that expose an edge case in template registration.

Related errors


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/bc2731b74790c68f.json. Report an issue: GitHub ↗.