gohugoio/hugo · error
must not provide more arguments than resource object and opt
Error message
must not provide more arguments than resource object and options
What it means
Hugo's `js.Babel` (also exposed as `babel`) template function accepts at most two arguments: a JS Resource and an optional options map. If more than two are supplied it fails immediately before resolving the resource or decoding Babel options.
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 8a468df065)
Solutions
- Collapse all options into one dict: `{{ $built := js.Babel $js (dict "config" "babel.config.js" "minified" true) }}`.
- With pipes, pass at most the options before the pipe: `{{ $js | babel $opts }}`.
- Verify each option is a key in the dict, not a separate argument.
Example fix
<!-- before -->
{{ $out := js.Babel $js "minified" true }}
<!-- after -->
{{ $out := js.Babel $js (dict "minified" true) }} Defensive patterns
Strategy: validation
Validate before calling
{{ $js := resources.Get "main.js" }}
{{ $opts := dict "minify" true "target" "es2018" }}
{{ $built := $js | js.Build $opts }} Prevention
- js.Build takes at most two args: options and the resource; merge all settings into a single options dict rather than passing them separately
- With pipes, pass only the options dict before `| js.Build` — the resource arrives via the pipe
- Centralize build options in one `dict` variable so call sites stay two-argument
When it happens
Trigger: `{{ js.Babel $js $opts "extra" }}` or a pipe form that adds up to three arguments, e.g. `{{ $js | babel $opts1 $opts2 }}`.
Common situations: Passing options as separate positional arguments instead of a single dict (`{{ babel $js "compact" true }}` rather than `{{ babel $js (dict "compact" true) }}`), or copying js.Build examples and appending stray parameters.
Related errors
- need at least 2 arguments to append
- must provide a Resource and optionally an options map
- operator argument must be string type
- can't evaluate the array by no match argument or more than o
- invalid arguments supplied to `time`
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/19983ef69687735f.json.
Report an issue: GitHub ↗.