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

  1. Collapse all options into one dict: `{{ $built := js.Babel $js (dict "config" "babel.config.js" "minified" true) }}`.
  2. With pipes, pass at most the options before the pipe: `{{ $js | babel $opts }}`.
  3. 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

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


AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31). Data as JSON: /data/errors/19983ef69687735f.json. Report an issue: GitHub ↗.