{"record":{"id":"544e3cac5dd986b5","repo":"gohugoio/hugo","slug":"failed-to-build-js-bundle-w","errorCode":null,"errorMessage":"failed to build JS bundle: %w","messagePattern":"failed to build JS bundle: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"internal/js/esbuild/batch.go","lineNumber":625,"sourceCode":"\t\t\t\t}\n\t\t\t\treturn nil\n\t\t\t},\n\t\t\tResolveSourceMapSource: func(s string) string {\n\t\t\t\tif r, found := state.importResource.Get(s); found {\n\t\t\t\t\tif ss := resources.InternalResourceSourcePath(r); ss != \"\" {\n\t\t\t\t\t\treturn ss\n\t\t\t\t\t}\n\t\t\t\t\treturn PrefixHugoMemory + s\n\t\t\t\t}\n\t\t\t\treturn \"\"\n\t\t\t},\n\t\t\tEntryPoints: entryPoints,\n\t\t},\n\t}\n\n\tresult, err := b.client.buildClient.Build(jsOpts)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to build JS bundle: %w\", err)\n\t}\n\n\tgroups := make(map[string]resource.Resources)\n\n\tcreateAndAddResource := func(targetPath, group string, o api.OutputFile, mt media.Type) error {\n\t\tvar sourceFilename string\n\t\tif r, found := state.importResource.Get(targetPath); found {\n\t\t\tsourceFilename = resources.InternalResourceSourcePathBestEffort(r)\n\t\t}\n\t\ttargetPath = path.Join(b.id, targetPath)\n\n\t\trd := resources.ResourceSourceDescriptor{\n\t\t\tLazyPublish: true,\n\t\t\tOpenReadSeekCloser: func() (hugio.ReadSeekCloser, error) {\n\t\t\t\treturn hugio.NewReadSeekerNoOpCloserFromBytes(o.Contents), nil\n\t\t\t},\n\t\t\tMediaType:            mt,\n\t\t\tTargetPath:           targetPath,","sourceCodeStart":607,"sourceCodeEnd":643,"githubUrl":"https://github.com/gohugoio/hugo/blob/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/internal/js/esbuild/batch.go#L607-L643","documentation":"Returned by the batch build path when esbuild's Build() call itself returns a non-nil error, as opposed to producing OutputFiles with errors attached. The wrapped error is the real esbuild failure (option validation, plugin Setup panic, or a hard build failure).","triggerScenarios":"b.client.buildClient.Build(jsOpts) returns err != nil at batch.go:623-625. This is the synchronous failure path of esbuild itself, typically invalid option combinations or an internal Hugo plugin Setup callback that errored, rather than per-file syntax errors (those surface via result.Errors).","commonSituations":"Incompatible esbuild option combinations (e.g., Splitting without Format=esm); an outdated bundled esbuild version that rejects a configured option; a plugin Setup panic; very large builds exhausting memory.","solutions":["Inspect the wrapped error (the %w) — it is the actual cause; treat the outer message as a wrapper only.","Reduce the batch to a single entrypoint to isolate which option triggers the failure.","Verify the esbuild version bundled with your Hugo release against the option you are setting.","If the wrapped error points to an internal Hugo plugin Setup issue, report it upstream with the unwrapped message."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"Capture the error from Build(), then errors.Unwrap to log the underlying esbuild message separately from the Hugo wrapper. Distinguish a hard esbuild failure from per-file Errors before reporting.","preventionTips":["Pin a known-good Hugo release so the bundled esbuild version is predictable.","Keep batch entrypoints small and cohesive to narrow failure scope.","Remember Splitting requires Format=esm; do not mix incompatible options."],"tags":["esbuild","batch","build"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}