gohugoio/hugo · error
unsupported platform type: %q
Error message
unsupported platform type: %q
What it means
The `platform` option selects esbuild's target platform, which affects package.json main-field resolution, default output conventions, and how built-ins are treated. Hugo accepts only "" or "browser" (default), "node", and "neutral"; other values abort with this error.
Source
Thrown at internal/js/esbuild/options.go:380
case "preserve":
jsx = api.JSXPreserve
case "automatic":
jsx = api.JSXAutomatic
default:
err = fmt.Errorf("unsupported jsx type: %q", opts.JSX)
return
}
var platform api.Platform
switch opts.Platform {
case "", "browser":
platform = api.PlatformBrowser
case "node":
platform = api.PlatformNode
case "neutral":
platform = api.PlatformNeutral
default:
err = fmt.Errorf("unsupported platform type: %q", opts.Platform)
return
}
var defines map[string]string
if opts.Defines != nil {
defines = hmaps.ToStringMapString(opts.Defines)
}
var drop api.Drop
switch opts.Drop {
case "":
case "console":
drop = api.DropConsole
case "debugger":
drop = api.DropDebugger
default:
err = fmt.Errorf("unsupported drop type: %q", opts.Drop)
}View on GitHub ↗ (pinned to 8a468df065)
Solutions
- Use "browser", "node", or "neutral" as the platform value.
- Remove the option to default to "browser", which is correct for almost all Hugo sites.
- If targeting a runtime-agnostic library build, use "neutral".
Example fix
{{/* before */}}
{{ $js := resources.Get "main.js" | js.Build (dict "platform" "web") }}
{{/* after */}}
{{ $js := resources.Get "main.js" | js.Build (dict "platform" "browser") }} Defensive patterns
Strategy: validation
Validate before calling
validPlatforms := map[string]bool{"browser": true, "node": true, "neutral": true}
if opts.Platform != "" && !validPlatforms[opts.Platform] {
return fmt.Errorf("invalid platform %q; must be browser, node, or neutral", opts.Platform)
} Prevention
- Stick to browser (default), node, or neutral for the platform option.
- For code shipped to a website, omit platform entirely and take the browser default.
- Validate option maps passed through dict/site params before they reach js.Build.
When it happens
Trigger: Passing `dict "platform" "web"`, "nodejs", "deno", or any string other than browser/node/neutral to js.Build/js.Batch options.
Common situations: Writing "web" out of habit from other tools; "nodejs" instead of "node"; casing mistakes like "Browser" won't fail (option keys are case-insensitive but values are not) — the value must be exact lowercase.
Related errors
- inject: absolute paths not supported, must be relative to /a
- invalid engine version: %q
- unsupported target: %v
- invalid loader: %q
- unsupported script output format: %q
AI-assisted analysis of gohugoio/hugo@8a468df065 (2026-07-31).
Data as JSON: /data/errors/f83215e3f424d7f2.json.
Report an issue: GitHub ↗.