gohugoio/hugo · error
no Resource provided in transformation
Error message
no Resource provided in transformation
What it means
ResolveArgs backs Hugo's resource-transformation template functions (resources.Minify, resources.Fingerprint, resources.PostCSS, resources.Babel, etc.), which accept `(resource)` or `(options, resource)` to support both call and pipeline styles. With zero args there is no resource to transform, so Hugo errors immediately. The same message is also reused at line 58 when two args are given but the second is neither a ResourceTransformer nor an options map.
Source
Thrown at tpl/internal/resourcehelpers/helpers.go:44
// We allow string or a map as the first argument in some cases.
func ResolveIfFirstArgIsString(args []any) (resources.ResourceTransformer, string, bool) {
if len(args) != 2 {
return nil, "", false
}
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])
}
View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Ensure the resource exists and is passed: `{{ $css := resources.Get "css/main.css" }}{{ with $css }}{{ .| minify }}{{ end }}`.
- Guard against nil from resources.Get with `with` or an explicit errorf.
- In pipelines, options come first: `$r | resources.PostCSS $opts` is `PostCSS $opts $r`.
Example fix
<!-- before -->
{{ $css := resources.Get "css/mian.css" | minify }}
<!-- after -->
{{ $css := resources.Get "css/main.css" }}
{{ with $css }}{{ $min := . | minify }}{{ end }} Defensive patterns
Strategy: validation
Validate before calling
{{ $img := resources.Get "logo.png" }}
{{ if $img }}{{ $small := $img.Resize "200x" }}{{ else }}{{ warnf "logo.png not found" }}{{ end }} Prevention
- Always nil-check the result of resources.Get / .Resources.Get before piping into a transformation
- Pass the resource explicitly as the last argument when using function-style calls (e.g. images.Filter)
- Fail loudly with errorf for required assets instead of silently skipping
When it happens
Trigger: Calling a transform with no arguments: `{{ resources.Minify }}`, or a broken pipeline where the piped resource evaluates to nothing; two-arg calls where the second argument is not a resource or map.
Common situations: `resources.Get` returned nil (missing asset file) and the nil was piped into Minify/Fingerprint; partial refactors that dropped the resource argument; wrong pipe order putting options last.
Related errors
- type %T not supported in Resource transformations
- invalid options type: %w
- no Key set in Resource
- resources.PostProcess cannot be used in a deferred template
- must not provide more arguments than Resource and hash algor
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/b235d147062008c2.json.
Report an issue: GitHub ↗.