{"record":{"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/52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2/internal/js/esbuild/batch.go#L325-L361","documentation":"The batcher.Build entry point (batch.go:337-345) fetches-or-creates the batch via a dynacache store, calling the internal build(). If build() returns an error, Build wraps it with the batch id (%q) via %w. This is the top-level failure for a JS batch and aggregates all downstream causes (template execution, esbuild bundling, resource creation, group builds).","triggerScenarios":"Any failure inside build(): a template error in the batch runner template, esbuild failing to bundle (syntax error, missing import, unsupported format), resource creation errors, or the 'only esm format' check. The id names which batch failed.","commonSituations":"A JS import typo or missing dependency surfaced through esbuild; a batch group template error; passing a non-esm format; a resource FromString failure due to invalid generated JS.","solutions":["Unwrap the %w to find the concrete cause (esbuild error message, template error, etc.).","If it is an esbuild error, open the offending JS/TS entry and fix the syntax/import.","If it is 'only esm format is currently supported', set options.Format to \"esm\" (or leave empty).","Rebuild after fixing; clear the dynacache if stale artifacts persist."],"exampleFix":"// before: options.Format = \"iife\"\n// error: failed to build JS batch \"main\": only esm format is currently supported\n\n// after\noptions.Format = \"esm\"","handlingStrategy":"try-catch","validationCode":"func safeBuild(ctx context.Context, b *batcher) (js.BatchPackage, error) {\n    pkg, err := b.Build(ctx)\n    if err != nil {\n        return nil, fmt.Errorf(\"batch build failed: %w\", err)\n    }\n    return pkg, nil\n}","typeGuard":null,"tryCatchPattern":"pkg, err := batcher.Build(ctx)\nif err != nil {\n    var fe *fmt.Errorf // unwrap to inspect underlying esbuild/template cause\n    log.Printf(\"batch build error: %+v\", err)\n    return err\n}","preventionTips":["Validate JS entry points and imports before building batches.","Keep options.Format as \"esm\" (or unset).","Clear the dynacache when build inputs change to avoid stale artifacts."],"tags":["esbuild","batch","js","build","hugo"],"backgroundTag":null,"analyzedSha":"52c9bd7908b4d02d4d0ff8f82a888834d6ee10d2","analyzedAt":"2026-08-09T21:49:36.660Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}