{"id":"4ff9a5e738cd9740","repo":"gohugoio/hugo","slug":"only-esm-format-is-currently-supported","errorCode":null,"errorMessage":"only esm format is currently supported","messagePattern":"only esm format is currently supported","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/esbuild/batch.go","lineNumber":527,"sourceCode":"\t\t}\n\n\t\tstate.importerImportContext.Set(s, importContext{\n\t\t\tname:           s,\n\t\t\tresourceGetter: nil,\n\t\t\tdm:             g.dependencyManager,\n\t\t})\n\n\t\taddResource(g.id, s, r, true)\n\t}\n\n\tmediaTypes := b.client.d.ResourceSpec.MediaTypes()\n\n\texternalOptions := b.configOptions.Compiled().Options\n\tif externalOptions.Format == \"\" {\n\t\texternalOptions.Format = \"esm\"\n\t}\n\tif externalOptions.Format != \"esm\" {\n\t\treturn nil, fmt.Errorf(\"only esm format is currently supported\")\n\t}\n\n\tjsOpts := Options{\n\t\tExternalOptions: externalOptions,\n\t\tInternalOptions: InternalOptions{\n\t\t\tDependencyManager: b.dependencyManager,\n\t\t\tSplitting:         true,\n\t\t\tImportOnResolveFunc: func(imp string, args api.OnResolveArgs) string {\n\t\t\t\tvar importContextPath string\n\t\t\t\tif args.Kind == api.ResolveEntryPoint {\n\t\t\t\t\timportContextPath = args.Path\n\t\t\t\t} else {\n\t\t\t\t\timportContextPath = args.Importer\n\t\t\t\t}\n\t\t\t\timportContext, importContextFound := state.importerImportContext.Get(importContextPath)\n\n\t\t\t\t// We want to track the dependencies closest to where they're used.\n\t\t\t\tdm := b.dependencyManager","sourceCodeStart":509,"sourceCodeEnd":545,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/internal/js/esbuild/batch.go#L509-L545","documentation":"`js.Batch` relies on esbuild code splitting (`Splitting: true`), which esbuild only supports for ESM output. Hugo defaults the batch format to \"esm\" when unset, but if the batch config explicitly sets any other format it refuses to build with this error.","triggerScenarios":"Setting `format` to \"iife\" or \"cjs\" in a batch's config options (`{{ with .Config }}{{ .SetOptions (dict \"format\" \"iife\") }}{{ end }}`) and then building the batch.","commonSituations":"Reusing js.Build option dicts (where iife is the default and valid) for a js.Batch config; trying to support legacy browsers without module support via IIFE output; assuming batch supports the same formats as js.Build.","solutions":["Set the batch format to \"esm\" or simply omit the format option — esm is the default and the only supported value.","Load the output with `<script type=\"module\">` in your templates.","If you truly need IIFE/CJS output, use plain `js.Build` instead of `js.Batch` (losing code splitting)."],"exampleFix":"{{/* before */}}\n{{ .SetOptions (dict \"format\" \"iife\") }}\n{{/* after */}}\n{{ .SetOptions (dict \"format\" \"esm\") }}","handlingStrategy":"validation","validationCode":"// In config for a js.Batch group:\nif opts.Format != \"\" && opts.Format != \"esm\" {\n    return errors.New(\"js.Batch only supports format \\\"esm\\\"; remove the format option or set it to esm\")\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't set format at all in js.Batch config — esm is the only supported value and the default.","If you need iife/cjs output, use js.Build for that script instead of putting it in a batch.","Audit shared option dicts reused between js.Build and js.Batch; options valid for one aren't always valid for the other."],"tags":["hugo","esbuild","js-batch","esm","code-splitting","config"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}