Backtestshugorun-20260930-140149#15307

Issue #15307 Merged fix PR # Run 30 Sep 2026 · run-20260930-140149 gohugoio/hugo

js.Build should support es2025 as target

Better

Our patch was judged better than the merged fix.

In this judgment, Patch B = our agent, Patch A = the merged fix.

Both patches make the same core change: they add "es2025": api.ES2025 to the target map in internal/js/esbuild/options.go. That fixes the root cause of the 'unsupported target: [es2025]' error. Both also extend TestToBuildOptionsTarget with es2024 and es2025 cases, which would fail before the change and pass after. On correctness and the unit test, they are equivalent. Patch B adds two things. First, it updates the user-facing docs (options.md) that list valid targets. The issue explicitly complains that es2025 isn't 'listed' as an available target, so this is directly in scope. Second, it adds an integration test that mirrors the issue's reproduction: a TS file passed through js.Build with minify, sourceMap none and target es2025. That test exercises the full template path the reporter hit. Its exact-output assertion on minified code (variable name 'o') is somewhat brittle against future esbuild changes. Even so, it is a real end-to-end regression test, not a tautological one. Because B covers the documentation half of the issue's ask and adds stronger end-to-end coverage, with no added risk, B is the better fix.

The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.

Solve

16m 25s16 turns

Wall-clock time in the container

Full test suite

No new failures

3,758 passed · 100 skipped · 3,860 total

Contamination audit

Clean

No sign the agent saw the real fix

Patch size

22vs 3 merged

Changed lines, ours vs merged

Hugo's built-in js.Build function currently doesnt support and/or list es2025 as available target parameter.
As far as i understood js.Build relies on evanw/esbuild for bundling, transforming and minifying javascript ressources.

According to hugo's own release notes esbuild was just bumped to 0.28.2.
According to esbuild's release notes, support for es2025 as target parameter exists since 0.27.5.
Hugo should therefore support es2025 as target parameter.

However when doing something like this:

{{- $buildParams := dict
    "minify" true
    "sourceMap" "none"
    "target" "es2025"
}}
{{- with . | js.Build $buildParams }}
    <script>{{ .Content | safeJS }}</script>
{{- end }}

results in the following error message:
`
... JSBUILD: failed to transform "/ts/test.ts" (text/typescript): unsupported target: [es2025] ...
`

What version of Hugo are you using (hugo version)?

hugo v0.165.0

Does this issue reproduce with the latest release?

Yes

The two patches

Our patch+21 −1
docs/content/en/_common/functions/js/options.mdindex ed606b0d7..4767eda6c 100644@@ -104,4 +104,4 @@ _comment: Do not remove front matter. : (`bool`) Whether to include the content of the source files in the source map. Default is `true`.  `target`-: (`string`) The language target. One of: `es5`, `es2015`, `es2016`, `es2017`, `es2018`, `es2019`, `es2020`, `es2021`, `es2022`, `es2023`, `es2024`, or `esnext`. Default is `esnext`.+: (`string`) The language target. One of: `es5`, `es2015`, `es2016`, `es2017`, `es2018`, `es2019`, `es2020`, `es2021`, `es2022`, `es2023`, `es2024`, `es2025`, or `esnext`. Default is `esnext`.internal/js/esbuild/options.goindex 4176438e8..9248701f7 100644@@ -49,6 +49,7 @@ var ( 		"es2022": api.ES2022, 		"es2023": api.ES2023, 		"es2024": api.ES2024,+		"es2025": api.ES2025, 	}  	engineName = map[string]api.EngineName{internal/js/esbuild/options_test.goindex b60dcbc4a..683a32db0 100644@@ -189,6 +189,8 @@ func TestToBuildOptionsTarget(t *testing.T) { 		{"es2021", api.ES2021}, 		{"es2022", api.ES2022}, 		{"es2023", api.ES2023},+		{"es2024", api.ES2024},+		{"es2025", api.ES2025}, 		{"", api.ESNext}, 		{"esnext", api.ESNext}, 	} {resources/resource_transformers/js/js_integration_test.goindex 2244e8f8e..2781d55dc 100644@@ -448,3 +448,20 @@ JS Content:{{ $js.Content }}:End: 	b.Assert(err.Error(), qt.Contains, `execute of template failed: template: home.html:2:17`) 	b.Assert(err.Error(), qt.Contains, `main.js:1:31": Could not resolve "./util1"`) }++func TestBuildTargetES2025(t *testing.T) {+	t.Parallel()+	files := `+-- hugo.toml --+disableKinds = ['RSS','sitemap','taxonomy','term']+-- assets/ts/test.ts --+const greeting: string = "Hello ES2025";+console.log(greeting);+-- layouts/home.html --+{{ with resources.Get "ts/test.ts" | js.Build (dict "minify" true "sourceMap" "none" "target" "es2025") }}+<script>{{ .Content | safeJS }}</script>+{{ end }}+`+	b := hugolib.Test(t, files, hugolib.TestOptOsFs())+	b.AssertFileContent("public/index.html", `<script>(()=>{var o="Hello ES2025";console.log(o);})();`)+} 
Merged fix · PR #+3 −0
internal/js/esbuild/options.goindex 4176438e8..9248701f7 100644@@ -49,6 +49,7 @@ var ( 		"es2022": api.ES2022, 		"es2023": api.ES2023, 		"es2024": api.ES2024,+		"es2025": api.ES2025, 	}  	engineName = map[string]api.EngineName{internal/js/esbuild/options_test.goindex b60dcbc4a..683a32db0 100644@@ -189,6 +189,8 @@ func TestToBuildOptionsTarget(t *testing.T) { 		{"es2021", api.ES2021}, 		{"es2022", api.ES2022}, 		{"es2023", api.ES2023},+		{"es2024", api.ES2024},+		{"es2025", api.ES2025}, 		{"", api.ESNext}, 		{"esnext", api.ESNext}, 	} { 

What the agent reported

js.Build now accepts "target" "es2025". The new tests fail without the fix and pass with it, but I had to run them with go test directly because ./bt-test couldn't build anything in its container.

What was wrong: Hugo checks the target name against a fixed list in internal/js/esbuild/options.go. That list stopped at es2024, so es2025 produced unsupported target: [es2025] before esbuild was ever called. The esbuild version Hugo uses (v0.28.2) already supports ES2025.

What I changed:

  • internal/js/esbuild/options.go: added "es2025": api.ES2025, to the list of accepted targets.
  • docs/content/en/_common/functions/js/options.md: added es2025 to the documented target list.
  • internal/js/esbuild/options_test.go: added es2024 and es2025 cases to TestToBuildOptionsTarget.
  • resources/resource_transformers/js/js_integration_test.go: added TestBuildTargetES2025. It runs your exact template (minify true, sourceMap "none", target "es2025", output via <script>{{ .Content | safeJS }}</script>) on a TypeScript file. It checks that the page contains the minified script: <script>(()=>{var o="Hello ES2025";console.log(o);})();

Test evidence:

  • ./bt-test couldn't run: its container has no network and its Go module cache is empty, so every run stopped at [setup failed] while trying to download modules from proxy.golang.org. That's an environment problem, not a test result.
  • What I ran instead: go test with GOMODCACHE=/bt/cache/go-mod GOPROXY=off, which uses the local copy of the same pinned modules.
  • Before the fix: TestToBuildOptionsTarget/es2025 failed with unsupported target: [es2025]. TestBuildTargetES2025 failed with the error from your report: JSBUILD: failed to transform "/ts/test.ts" (text/typescript): unsupported target: [es2025].
  • After the fix: all tests in both packages (internal/js/esbuild and resources/resource_transformers/js) pass, including the two new ones.
  • Check that the test catches the bug: with only the fix temporarily removed, the integration test failed again with the same error.
  • Assertion fix: the first version of the integration test checked for the wrong text. I corrected it to match the real minified output before the final runs.
  • Possible fragility: the integration test expects esbuild's exact minified output. That output is stable while esbuild stays at v0.28.2, but a future esbuild upgrade could change it (for example, by renaming the variable).

Requirements:

  1. Accept es2025 as a js.Build target: done, proven by the unit test and the integration test.
  2. Your template no longer errors: done; TestBuildTargetES2025 reproduces it end to end.
  3. List es2025 as an available target: done in the docs. I checked that esbuild v0.28.2 actually provides ES2025 before adding it.

Nothing is committed. AGENTS.md and CLAUDE.md show as deleted in the working tree, but they were already deleted before this session and I left them alone.