gohugoio/hugo · error
no Resource provided in transformation
Error message
no Resource provided in transformation
What it means
Thrown by resourcehelpers.ResolveArgs (tpl/internal/resourcehelpers/helpers.go:44) when a resource transformation function (e.g. js.Build, css.Sass, toCSS, minify) is called with zero arguments. Resource-transforming template functions expect the resource to transform as a piped or positional argument; with no args there is nothing to transform.
Solutions
- Pipe the resource in: {{ $js := resources.Get "js/main.js" | js.Build }}.
- Check the resource is non-nil before transforming: {{ with resources.Get "js/main.js" }}{{ js.Build . }}{{ end }}.
- Verify the asset path exists under assets/ (resources.Get only looks in the asset filesystem).
- If using positional args, pass the resource first: {{ js.Build $resource (dict "targetPath" "main.js") }}.
Example fix
// before
{{ $bundled := js.Build (dict "targetPath" "app.js") }}
// after
{{ $r := resources.Get "js/app.js" }}
{{ $bundled := js.Build $r (dict "targetPath" "app.js") }} Defensive patterns
Strategy: validation
Validate before calling
// Confirm the resource exists before transforming:
{{ with resources.Get "js/main.js" }}
{{ $out := js.Build . }}
{{ end }} Type guard
// Go caller of resourcehelpers.ResolveArgs:
func isResourceTransformer(v any) bool {
_, ok := v.(resources.ResourceTransformer)
return ok
} Prevention
- Always pipe a resource into transformation functions.
- Use {{ with resources.Get ... }} to handle a possibly-missing asset.
- Verify the asset path is correct and the file lives under assets/.
- Pass the resource as the first positional arg, not only an options map.
When it happens
Trigger: Calling {{ js.Build }} with nothing piped in, or {{ (resources.Get "main.js").WrongMethod }} where the pipeline produces nil and is then passed; forgetting the pipe: {{ js.Build "opts" }} where the resource was intended but omitted.
Common situations: Refactoring a pipeline and accidentally dropping the resource; resources.Get returning nil because the path was wrong, then piping nil into js.Build; misreading docs and calling the function with only an options map.
Related errors
- invalid options type
- type %T not supported in Resource transformations
- both count and seq must be provided
- cannot encode an empty string
- cannot index slice/array with nil
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/b235d147062008c2.
Report an issue: GitHub.
Appendix: 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 52c9bd7908)