gohugoio/hugo · error
invalid output format configuration; wrong type for media…
Error message
invalid output format configuration; wrong type for media type, expected string (e.g. text/html), got %T
What it means
Thrown in the mapstructure decode hook (output/config.go:124) when a custom output format's 'mediaType' field is present but is neither a string nor an already-resolved media.Type. The %T shows the offending type. Hugo expects mediaType to be a string like "text/html".
Solutions
- Set mediaType to a plain string: mediaType = "text/html".
- If the value comes from a template or script, ensure it is serialized as a string scalar.
- Run hugo config to inspect the resolved value and confirm its type.
Example fix
# before [outputFormats.MYFORMAT] mediaType = ["text/html"] # after [outputFormats.MYFORMAT] mediaType = "text/html"
Defensive patterns
Strategy: type-guard
Validate before calling
// mediaType must be a string scalar before decode.
func ensureMediaTypeIsString(v any) error {
if _, ok := v.(string); !ok {
return fmt.Errorf("mediaType must be string, got %T", v)
}
return nil
} Type guard
func isStringScalar(v any) bool {
_, ok := v.(string)
return ok
} Try / catch
if err := output.DecodeConfig(mediaTypes, in); err != nil {
// Distinguish type errors from missing media types in the message.
return fmt.Errorf("outputFormats decode: %w", err)
} Prevention
- Quote mediaType values: mediaType = "text/html".
- Avoid list/scalar values for mediaType.
- Lint config for type consistency.
When it happens
Trigger: Setting mediaType to a number (mediaType = 123), a boolean, an array (mediaType = ["text/html"]), or a nested map; WeaklyTypedInput is on but does not cover the type mismatch for this specific non-string scalar.
Common situations: TOML/YAML config where mediaType is accidentally quoted as a list or left as a bare number; tooling that injects mediaType from a variable of the wrong type; migrating config and dropping the surrounding quotes incorrectly.
Related errors
- failed to decode output format configuration
- media type not found
- failed convert config to map
- OutputFormat with key
- --appendPort=false not supported when in multihost mode
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/fad4182b78b85c1a.
Report an issue: GitHub.
Appendix: 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 52c9bd7908)