gohugoio/hugo · error
must not provide more arguments than resource object and…
Error message
must not provide more arguments than resource object and options
What it means
Thrown by js.Babel (tpl/js/js.go:101) when more than two arguments are passed. Babel accepts at most a resource object and an options map, so len(args) > 2 is rejected before ResolveArgs is even called. This mirrors the signature constraints of other resource-transform functions but is checked explicitly here.
Solutions
- Pass at most two args: the resource and (optionally) one options map.
- Move all configuration into a single dict: {{ js.Babel $r (dict "sourceMap" "inline" "config" "babel.config.js") }}.
- If you need a target path, include it in the options map, not as a separate positional arg.
- Switch to js.Build if you actually wanted the esbuild-based string-first-arg form.
Example fix
// before
{{ js.Babel $r "app.js" (dict "sourceMap" "inline") }}
// after
{{ js.Babel $r (dict "targetPath" "app.js" "sourceMap" "inline") }} Defensive patterns
Strategy: validation
Validate before calling
// Babel takes resource + one optional options map; do not pass a third arg:
{{ $opts := dict "sourceMap" "inline" }}
{{ js.Babel $r $opts }} Type guard
// Go caller: enforce arg count before calling Babel:
func validBabelArgs(args []any) bool { return len(args) <= 2 } Prevention
- Remember js.Babel accepts at most two args (resource + options).
- Do not reuse the js.Build string-first-arg form with Babel.
- Bundle all settings into a single options map.
When it happens
Trigger: Calling {{ js.Babel $r $opts $extra }}, or accidentally passing a targetPath string plus a resource plus an options map (three positional args), which is the js.Build pattern but not valid for Babel.
Common situations: Confusing js.Babel's signature with js.Build (which supports a targetPath string first-arg form); copy-pasting a js.Build invocation and only swapping the function name; passing extra positional args meant as options.
Related errors
- both count and seq must be provided
- cannot encode an empty string
- cannot index slice/array with nil
- complement needs at least two arguments
- error correction level must be one of low, medium…
AI-assisted analysis of gohugoio/hugo@52c9bd7908 (2026-08-09).
Data as JSON: /api/errors/19983ef69687735f.
Report an issue: GitHub.
Appendix: source
Thrown at tpl/js/js.go:101
// Forward slashes in the ID is allowed.
func (ns *Namespace) Batch(id string) (js.Batcher, error) {
if err := esbuild.ValidateBatchID(id, true); err != nil {
return nil, err
}
b, err := ns.d.JSBatcherClient.Store().GetOrCreate(id, func() (js.Batcher, error) {
return ns.d.JSBatcherClient.New(id)
})
if err != nil {
return nil, err
}
return b, nil
}
// Babel processes the given Resource with Babel.
func (ns *Namespace) Babel(args ...any) (resource.Resource, error) {
if len(args) > 2 {
return nil, errors.New("must not provide more arguments than resource object and options")
}
r, m, err := resourcehelpers.ResolveArgs(args)
if err != nil {
return nil, err
}
var options babel.Options
if m != nil {
options, err = babel.DecodeOptions(m)
if err != nil {
return nil, err
}
}
return ns.babelClient.Process(r, options)
}
View on GitHub (pinned to 52c9bd7908)