gohugoio/hugo · error
type %T not supported in Resource transformations
Error message
type %T not supported in Resource transformations
What it means
A single argument was passed to a resource transformation but it does not implement resources.ResourceTransformer — the interface all pipeable Hugo assets satisfy. The %T verb reports the actual concrete type so the author can see what was piped in instead of a resource. It also fires in the two-arg path when args[1] is a plain map (options in the resource slot).
Source
Thrown at tpl/internal/resourcehelpers/helpers.go:50
v1, ok1 := args[0].(string)
if !ok1 {
return nil, "", false
}
v2, ok2 := args[1].(resources.ResourceTransformer)
return v2, v1, ok2
}
// This roundabout way of doing it is needed to get both pipeline behavior and options as arguments.
func ResolveArgs(args []any) (resources.ResourceTransformer, map[string]any, error) {
if len(args) == 0 {
return nil, nil, errors.New("no Resource provided in transformation")
}
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, nilView on GitHub ↗ (pinned to 8a468df065)
Solutions
- Fetch a real resource first: `{{ $r := resources.Get "css/main.css" }}{{ $r | minify }}`.
- Check argument order for two-arg transforms: options first, resource last (`resources.PostCSS $opts $r` or `$r | resources.PostCSS $opts`).
- Print the offending type with `printf "%T"` to see what you actually passed.
Example fix
<!-- before -->
{{ $min := "css/main.css" | minify }}
<!-- after -->
{{ $min := resources.Get "css/main.css" | minify }} Defensive patterns
Strategy: type-guard
Validate before calling
{{ $r := resources.Get "data.json" }}
{{ if $r }}{{ $min := $r | minify }}{{ end }} Type guard
{{/* ensure the value is a Resource, not a string path or Page */}}
{{ if reflect.IsMap $r }}{{ errorf "expected a Resource, got a map" }}{{ end }} Prevention
- Pass an actual Resource object, not a URL string or file path, to fingerprint/minify/toCSS etc.
- Fetch remote assets with resources.GetRemote first, then transform the returned resource
- Don't pass Pages or plain strings into resource transformation pipelines
When it happens
Trigger: `{{ "css/main.css" | minify }}` (a string, not a resource); piping a Page, nil, or plain map into fingerprint/minify/toCSS; passing options where the resource should be.
Common situations: Confusing a file path string with a resource (must call resources.Get first); piping the result of readFile (a string) into a transform; page resources fetched with the wrong method returning a different type.
Related errors
- no Resource provided in transformation
- invalid options type: %w
- arguments to complement must be slices or arrays
- no Key set in Resource
- resources.PostProcess cannot be used in a deferred template
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/104d69fb1a6987aa.json.
Report an issue: GitHub ↗.