gohugoio/hugo · error
media type %q not found
Error message
media type %q not found
What it means
Raised in the output-format decode hook (output/config.go:120) when an output format's mediaType field names a media type that isn't registered. Hugo resolves the string (e.g. "text/html") against the site's configured media types via mediaTypes.GetByType; if there's no match, the output format cannot be wired to a MIME type and config decoding fails.
Source
Thrown at output/config.go:120
for _, key := range dataVal.MapKeys() {
keyStr, ok := key.Interface().(string)
if !ok {
// Not a string key
continue
}
if strings.EqualFold(keyStr, "mediaType") {
// If mediaType is a string, look it up and replace it
// in the map.
vv := dataVal.MapIndex(key)
vvi := vv.Interface()
switch vviv := vvi.(type) {
case media.Type:
// OK
case string:
mediaType, found := mediaTypes.GetByType(vviv)
if !found {
return c, fmt.Errorf("media type %q not found", vviv)
}
dataVal.SetMapIndex(key, reflect.ValueOf(mediaType))
default:
return nil, fmt.Errorf("invalid output format configuration; wrong type for media type, expected string (e.g. text/html), got %T", vvi)
}
}
}
}
return c, nil
},
}
decoder, err := mapstructure.NewDecoder(config)
if err != nil {
return err
}
if err = decoder.Decode(input); err != nil {View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Declare the custom media type in [mediaTypes] before referencing it: add a [mediaTypes.'<type/subtype>'] block with its suffixes.
- Fix typos — mediaType must exactly match a known type like text/html, application/json, text/calendar.
- When copying an outputFormats definition from another project, copy its mediaTypes definition too.
- Run 'hugo config' to inspect the effective mediaTypes list your build knows about.
Example fix
# before [outputFormats.MyFeed] mediaType = "application/x-myfeed" # after [mediaTypes.'application/x-myfeed'] suffixes = ["myfeed"] [outputFormats.MyFeed] mediaType = "application/x-myfeed"
Defensive patterns
Strategy: validation
Validate before calling
// Every mediaType named in outputFormats must exist in mediaTypes config [mediaTypes.'application/vnd.api+json'] suffixes = ['json'] [outputFormats.api] mediaType = 'application/vnd.api+json'
Prevention
- Define custom media types under `mediaTypes` before referencing them in `outputFormats`
- Use exact full type strings (e.g. `text/html`, not `html`) — lookup is by the full type name
- Run `hugo config` in CI to validate the output format/media type wiring
When it happens
Trigger: Decoding [outputFormats] configuration where mediaType is a string not present in the (built-in plus [mediaTypes]-defined) media type set — including custom types used before being declared, or lookups happening in a context where the custom [mediaTypes] block wasn't merged.
Common situations: Typos like "text/htm" or "application/josn"; defining a custom output format with mediaType = "application/x-foo" without a matching [mediaTypes.'application/x-foo'] block; copying output-format snippets between sites without also copying the mediaTypes definition; suffix-style values ("json") where a full type/subtype is required.
Related errors
- failed to resolve output formats %v: %w
- invalid output format configuration; wrong type for media ty
- failed to decode output format configuration: %w
- unknown output format %q for kind %q
- unknown default output format %q
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/f0bec5f6f63afd96.json.
Report an issue: GitHub ↗.