gohugoio/hugo · error
invalid options type: %w
Error message
invalid options type: %w
What it means
In the two-argument form of a resource transformation, the resource was valid but the first argument (the options) could not be converted to map[string]any by hmaps.ToStringMapE. Hugo wraps the underlying conversion error with %w. Options for transforms like PostCSS, Babel, ToCSS, and Fingerprint variants must be a dict/map.
Source
Thrown at tpl/internal/resourcehelpers/helpers.go:65
if len(args) == 1 {
r, ok := args[0].(resources.ResourceTransformer)
if !ok {
return nil, nil, fmt.Errorf("type %T not supported in Resource transformations", args[0])
}
return r, nil, nil
}
r, ok := args[1].(resources.ResourceTransformer)
if !ok {
if _, ok := args[1].(map[string]any); !ok {
return nil, nil, fmt.Errorf("no Resource provided in transformation")
}
return nil, nil, fmt.Errorf("type %T not supported in Resource transformations", args[0])
}
m, err := hmaps.ToStringMapE(args[0])
if err != nil {
return nil, nil, fmt.Errorf("invalid options type: %w", err)
}
return r, m, nil
}
View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Wrap options in a dict: `{{ $r | resources.PostCSS (dict "config" "config.js") }}`.
- Check the specific transform's docs for its option keys (e.g. toCSS: targetPath, transpiler, vars).
- If building options dynamically, verify with `printf "%T"` that it is a map before passing.
Example fix
<!-- before -->
{{ $css := $scss | toCSS "main.css" }}
<!-- after -->
{{ $css := $scss | toCSS (dict "targetPath" "main.css") }} Defensive patterns
Strategy: validation
Validate before calling
{{ $opts := dict "targetPath" "css/main.css" "outputStyle" "compressed" }}
{{ $css := $scss | css.Sass $opts }} Type guard
{{/* options must be a map/dict, not a string or slice */}} Prevention
- Build transformation options with dict, never a bare string or slice
- Check the docs for each transformation's supported option keys — unknown shapes fail to decode
- Keep option values simple scalars/maps that map cleanly to the documented option struct
When it happens
Trigger: `{{ $r | resources.PostCSS "config.js" }}` or any transform given a string/slice/number as options instead of a dict, so ToStringMapE fails on the non-map type.
Common situations: Passing a config file path or preset name as a bare string where a dict is required; passing `slice` instead of `dict`; options built in a partial arriving as the wrong type.
Related errors
- no Resource provided in transformation
- type %T not supported in Resource transformations
- no Key set in Resource
- resources.PostProcess cannot be used in a deferred template
- failed to decode options: %w
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/c63e920577bb4a84.json.
Report an issue: GitHub ↗.