gohugoio/hugo · error

unsupported sourcemap type: %q

Error message

unsupported sourcemap type: %q

What it means

The `sourceMap` option maps to esbuild's source-map modes. Hugo accepts "inline", "external", "linked", or ""/"none"; anything else fails option compilation. "linked" emits a .map file plus a sourceMappingURL comment, "external" emits the .map without the comment, "inline" embeds it in the output.

Source

Thrown at internal/js/esbuild/options.go:414

	default:
		err = fmt.Errorf("unsupported drop type: %q", opts.Drop)
	}

	// By default we only need to specify outDir and no outFile
	outDir := opts.OutDir
	outFile := ""
	var sourceMap api.SourceMap
	switch opts.SourceMap {
	case "inline":
		sourceMap = api.SourceMapInline
	case "external":
		sourceMap = api.SourceMapExternal
	case "linked":
		sourceMap = api.SourceMapLinked
	case "", "none":
		sourceMap = api.SourceMapNone
	default:
		err = fmt.Errorf("unsupported sourcemap type: %q", opts.SourceMap)
		return
	}

	sourcesContent := api.SourcesContentInclude
	if !opts.SourcesContent {
		sourcesContent = api.SourcesContentExclude
	}

	if opts.IsCSS && opts.MainFields == nil {
		opts.MainFields = []string{"style", "main"}
	}

	opts.Vars = sass.PrepareVars(opts.Vars)

	opts.compiled = api.BuildOptions{
		Outfile:       outFile,
		Bundle:        true,
		Metafile:      opts.Metafile,

View on GitHub ↗ (pinned to 8a468df065)

Solutions

  1. Set sourceMap to "inline", "external", or "linked" (usually "linked" for dev).
  2. If "linked" fails on your Hugo version, upgrade Hugo or use "external".
  3. Remove the option or set "none" to disable source maps for production.

Example fix

{{/* before */}}
{{ $js := resources.Get "main.js" | js.Build (dict "sourceMap" true) }}
{{/* after */}}
{{ $js := resources.Get "main.js" | js.Build (dict "sourceMap" "linked") }}
Defensive patterns

Strategy: validation

Validate before calling

validSourceMap := map[string]bool{"": true, "inline": true, "external": true, "linked": true, "none": true}
if !validSourceMap[opts.SourceMap] {
    return fmt.Errorf("invalid sourcemap option %q; must be inline, external, linked, or none", opts.SourceMap)
}

Prevention

When it happens

Trigger: Passing `dict "sourceMap" "true"`, "both", "hidden", or other esbuild-CLI-only values to js.Build/js.Batch options.

Common situations: Using boolean-ish values ("true"/true) expecting webpack-style semantics; using esbuild's "both" mode which Hugo doesn't expose; older docs/examples predating the "linked" mode (added in newer Hugo versions — on old Hugo, "linked" itself triggers this error).

Related errors


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