{"id":"11be01f57c408dc6","repo":"gohugoio/hugo","slug":"failed-to-build-js-batch-q-w","errorCode":null,"errorMessage":"failed to build JS batch %q: %w","messagePattern":"failed to build JS batch %q: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/esbuild/batch.go","lineNumber":343,"sourceCode":"\n\tclient            *BatcherClient\n\tdependencyManager identity.Manager\n\n\tconfigOptions optionsGetSetter[scriptID, configOptions]\n\n\t// The last successfully built package.\n\t// If this is non-nil and not stale, we can reuse it (e.g. on server rebuilds)\n\tprevBuild *Package\n}\n\n// Build builds the batch if not already built or if it's stale.\nfunc (b *batcher) Build(ctx context.Context) (js.BatchPackage, error) {\n\tkey := dynacache.CleanKey(b.id + \".js\")\n\tp, err := b.client.bundlesStore.GetOrCreate(key, func() (js.BatchPackage, error) {\n\t\treturn b.build(ctx)\n\t})\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to build JS batch %q: %w\", b.id, err)\n\t}\n\treturn p, nil\n}\n\nfunc (b *batcher) Config(ctx context.Context) js.OptionsSetter {\n\treturn b.configOptions.Get(b.buildCount)\n}\n\nfunc (b *batcher) Group(ctx context.Context, id string) js.BatcherGroup {\n\tif err := ValidateBatchID(id, false); err != nil {\n\t\tpanic(err)\n\t}\n\n\tb.mu.Lock()\n\tdefer b.mu.Unlock()\n\n\tgroup, found := b.scriptGroups[id]\n\tif !found {","sourceCodeStart":325,"sourceCodeEnd":361,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/internal/js/esbuild/batch.go#L325-L361","documentation":"Wrapper error from `batcher.Build`, which builds a named `js.Batch` group through a dynacache store. Any failure inside the batch build — invalid options, esbuild compile errors, unresolved imports, script/instance validation — is wrapped with the batch ID via %w, so this is a context frame around an underlying cause.","triggerScenarios":"Executing a template that renders a `js.Batch \"someid\"` whose build fails: a syntax error in a batched script, a bad option in the batch config (see errors 520–524, 526), a missing import, or an esbuild bundling failure.","commonSituations":"Refactoring batched JS and introducing a compile error; misconfigured batch group options; imports of npm packages not installed in node_modules; stale cache issues on server rebuilds are handled, so the wrapped error is almost always a real build problem.","solutions":["Read the wrapped error after the batch ID — it names the actual failure (compile error, bad option, unresolved import) — and fix that root cause.","Run `hugo --logLevel debug` or `hugo server` to see the full esbuild diagnostics with file/line locations.","Verify the batch's config options (format, defines, etc.) are valid and that all imported packages exist."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Template-level: use try when consuming a JS batch group\n{{ with try (js.Batch \"mybatch\") }}\n  {{ with .Err }}{{ errorf \"JS batch failed: %s\" . }}{{ else }}{{/* use .Value */}}{{ end }}\n{{ end }}","preventionTips":["This error wraps an underlying esbuild failure — read the wrapped message; the root cause is usually a syntax error or unresolvable import in one of the batch's scripts.","Keep each batch script compiling standalone; test with hugo server before committing.","Pin JS dependency versions so imports don't break between builds.","Fail the build loudly (errorf) rather than emitting a page without its scripts."],"tags":["hugo","esbuild","js-batch","build-failure","wrapped-error"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}