gohugoio/hugo · error
ContentMediaType not set
Error message
ContentMediaType not set
What it means
Panic in getContentConverter: the page's ContentMediaType is the zero value when the converter is lazily initialized. The content converter is chosen based on ContentMediaType.SubType (markup), so an unset media type means the page's markup/content type was never configured during page decode. This indicates a page that bypassed the normal config-merge that sets the content media type.
Source
Thrown at hugolib/page.go:807
// wrapError adds some more context to the given error if possible/needed
func (ps *pageState) wrapError(err error) error {
return ps.m.wrapError(err, ps.s.h.SourceFs)
}
func (ps *pageState) getPageInfoForError() string {
s := fmt.Sprintf("kind: %q, path: %q", ps.Kind(), ps.Path())
if ps.File() != nil {
s += fmt.Sprintf(", file: %q", ps.File().Filename())
}
return s
}
func (ps *pageState) getContentConverter() converter.Converter {
var err error
ps.contentConverterInit.Do(func() {
if ps.m.pageConfigSource.ContentMediaType.IsZero() {
panic("ContentMediaType not set")
}
markup := ps.m.pageConfigSource.ContentMediaType.SubType
if markup == "html" {
// Only reachable for shortcode inner content rendering; file-based
// HTML pages are gated at initFrontMatter via security.allowContent.
markup = "markdown"
}
ps.contentConverter, err = ps.m.newContentConverter(ps, markup)
})
if err != nil {
ps.s.Log.Errorln("Failed to create content converter:", err)
}
return ps.contentConverter
}
func (ps *pageState) errorf(err error, format string, a ...any) error {View on GitHub (pinned to 52c9bd7908)
Solutions
- Ensure pages set their markup/content media type (e.g. assign pageConfigSource.ContentMediaType before content conversion).
- If hit on stock Hugo, report with the page path; it indicates a decode-path gap.
- Upgrade Hugo to the current release.
- For programmatic pages, set the markup explicitly in front matter (markup = 'markdown').
Example fix
{{/* content page missing markup resolution */}}
<!-- ensure front matter declares markup -->
+++
title = 'Post'
markup = 'markdown'
+++ Defensive patterns
Strategy: validation
Validate before calling
// Ensure pages declare markup so ContentMediaType is resolved. // Front matter: markup = 'markdown' (or rely on defaultMarkup in config). // For programmatic pages, set pageConfigSource.ContentMediaType before content conversion.
Prevention
- Always set markup in front matter or site defaultMarkup.
- Use standard page construction so config merge runs.
- Report stock-Hugo reproducers upstream.
- Upgrade Hugo.
When it happens
Trigger: A pageState whose pageConfigSource.ContentMediaType was never set (e.g. constructed manually, or a page kind/path that skipped the front-matter and markup resolution). Reaching getContentConverter before the page's media type is established. Usually an internal ordering/construction bug.
Common situations: Custom page kinds created programmatically without setting markup. A fork that builds pages without the standard config merge. A bug in headless-bundle or content-adapter page creation.
Related errors
- pageMeta.pageMetaSource.pi must be set before creating cache
- no content renderer found for markup %q, page: %s
- no site
- wrapError with nil
- no pageOutput
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/a403500b7a365138.
Report an issue: GitHub.