Backtestshugorun-20261007-020926#15307

Issue #15307 Merged fix PR #15308 Run 7 Oct 2026 · run-20261007-020926 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 root-cause fix: they add "es2025": api.ES2025 to the target map in internal/js/esbuild/options.go, which removes the 'unsupported target' error from the issue. Both also add es2024 and es2025 cases to the TestToBuildOptionsTarget unit test, which fails before the change and passes after. Correctness is therefore equal. Patch B is stronger on tests: it adds an end-to-end integration test (TestBuildTargetES2025) that reproduces the issue's scenario. That test runs js.Build on a TypeScript asset with target es2025, minify and sourceMap none, and asserts the output keeps an ES2025 regexp-modifier pattern. It would fail before the fix with the reported error. Patch B also updates the user-facing docs list of valid targets and corrects a stale code comment on ExternalOptions.Target. Without the docs change, es2025 would work but remain undocumented, which is part of the issue's complaint ('doesn't support and/or list'). These extras are low-risk and directly relevant, not churn. Patch B is the more complete 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

55m 19s

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

23vs 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 −2
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..3bdf3c66d 100644@@ -49,6 +49,7 @@ var ( 		"es2022": api.ES2022, 		"es2023": api.ES2023, 		"es2024": api.ES2024,+		"es2025": api.ES2025, 	}  	engineName = map[string]api.EngineName{@@ -144,7 +145,7 @@ type ExternalOptions struct { 	SourcesContent bool  	// This sets the target environment for the generated JavaScript and/or CSS code.-	// It can specify the JavaScript language version to target (es2015, es2016, es2017, es2018, es2019, es2020 or esnext; default is esnext),+	// It can specify the JavaScript language version to target (es5, es2015 through es2025, or esnext; default is esnext), 	// in addition to a set of environments to support, as slice of environment name followed by a version number. e.g. "chrome80", "firefox73", "safari13" or "edge80". 	// See https://esbuild.github.io/api/#target 	Target []stringinternal/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..b4d7e59d9 100644@@ -402,6 +402,22 @@ class A {} 	b.AssertFileContent("public/js/main.js", "__decorateClass") } +func TestBuildTargetES2025(t *testing.T) {+	t.Parallel()+	files := `+-- hugo.toml --+disableKinds = ['RSS','sitemap','taxonomy','term']+-- assets/ts/main.ts --+const re: RegExp = /(?i:a)b/;+console.log(re.test("Ab"));+-- layouts/home.html --+{{ $opts := dict "minify" true "sourceMap" "none" "target" "es2025" }}+{{ with resources.Get "ts/main.ts" | js.Build $opts }}<script>{{ .Content | safeJS }}</script>{{ end }}+`+	b := hugolib.Test(t, files, hugolib.TestOptOsFs())+	b.AssertFileContent("public/index.html", "<script>", "/(?i:a)b/")+}+ // Issue 13183. func TestExternalsInAssets(t *testing.T) { 	files := ` 
Merged fix · PR #15308+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}, 	} {