gohugoio/hugo · error
invalid output format configuration; wrong type for media ty
Error message
invalid output format configuration; wrong type for media type, expected string (e.g. text/html), got %T
What it means
Raised by the same decode hook (output/config.go:124) when an output format's mediaType value is neither an already-resolved media.Type nor a string. The hook only knows how to look up string values like "text/html"; a map, number, list, or other structure is a malformed configuration and is rejected with the offending Go type.
Source
Thrown at output/config.go:124
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 {
return fmt.Errorf("failed to decode output format configuration: %w", err)
}
return nilView on GitHub ↗ (pinned to 8a468df065)
Solutions
- Set mediaType to a plain string such as "text/html" in the output format definition.
- Move any suffix/structural configuration into a [mediaTypes.'<type>'] block and reference it by name from the output format.
- Validate generated config (YAML/JSON) to ensure mediaType serializes as a scalar string.
Example fix
# before (yaml)
outputFormats:
MyFormat:
mediaType:
type: text/html
# after
outputFormats:
MyFormat:
mediaType: text/html Defensive patterns
Strategy: type-guard
Validate before calling
// In outputFormats config, mediaType must be a plain string:
[outputFormats.myformat]
mediaType = 'text/html' # correct
# mediaType = { type = 'text/html' } # wrong: table/map, will fail Type guard
func validMediaTypeValue(v any) bool { _, ok := v.(string); return ok } Prevention
- Set `mediaType` as a string like `text/html`, never a nested table/map object
- When generating config programmatically (JSON/YAML), ensure serializers don't emit objects for mediaType
- Validate config with a dry build after editing outputFormats
When it happens
Trigger: Decoding [outputFormats] config where mediaType is given as a table/map (e.g. an inline object with type/suffixes fields), a list, or a number instead of a plain "type/subtype" string.
Common situations: Confusing the [mediaTypes] definition shape (which is a table with suffixes) with the outputFormats reference (which must be a string); YAML config where mediaType is accidentally nested as a mapping; programmatic config generation emitting an object instead of a string.
Related errors
- failed to resolve output formats %v: %w
- media type %q not found
- 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/fad4182b78b85c1a.json.
Report an issue: GitHub ↗.