{"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":"error","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/8a468df065a75c1c7cf9f6850f32148746590ea5/internal/js/esbuild/batch.go#L607-L643","documentation":"Wrapper around the actual esbuild invocation inside a batch build: after assembling entry points, virtual-import resolvers, and load hooks, Hugo calls `buildClient.Build(jsOpts)`. If esbuild reports errors (syntax errors, unresolvable imports, loader failures), they are wrapped with this message. It sits beneath error 525 in the chain.","triggerScenarios":"Any esbuild compile/bundle failure of the batch's combined entry points: a JS/TS syntax error in a batched script or runner, an import that neither the virtual Hugo resource resolver nor node_modules can satisfy, or a failing OnLoad reading a resource's content.","commonSituations":"Missing npm dependencies after cloning a site without running npm install; importing a Hugo resource path that doesn't exist so resolution falls through; TypeScript syntax in a file with a .js extension; version bumps changing script APIs.","solutions":["Inspect the wrapped esbuild error messages — they include the resolved source file and line; fix the reported syntax/import problem.","Run `npm install` (or equivalent) so bare-specifier imports resolve from node_modules.","Check that resource imports in batched scripts point at real assets and that params/instances are registered before the build."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"{{ with try (resources.Get \"js/main.js\" | js.Build $opts) }}\n  {{ with .Err }}{{ errorf \"JS bundle failed: %s\" . }}{{ else }}\n    <script src=\"{{ .Value.RelPermalink }}\"></script>\n  {{ end }}\n{{ end }}","preventionTips":["Read the wrapped esbuild diagnostics — they name the exact file/line (missing import, TS syntax error, bad loader).","Run npm install (or equivalent) before hugo when scripts import node_modules packages.","Configure defines/shims for browser builds of packages that reference process.env.","Treat bundle errors as build failures; never fall back to serving stale bundled output."],"tags":["hugo","esbuild","js-batch","bundling","imports"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}