{"id":"e3934444a3ca6ec9","repo":"gohugoio/hugo","slug":"unsupported-script-output-format-q","errorCode":null,"errorMessage":"unsupported script output format: %q","messagePattern":"unsupported script output format: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/esbuild/options.go","lineNumber":354,"sourceCode":"\t\tloader = api.LoaderJSX\n\tcase media.Builtin.CSSType.SubType:\n\t\tloader = api.LoaderCSS\n\tdefault:\n\t\terr = fmt.Errorf(\"unsupported Media Type: %q\", opts.MediaType)\n\t\treturn\n\t}\n\n\tvar format api.Format\n\t// One of: iife, cjs, esm\n\tswitch opts.Format {\n\tcase \"\", \"iife\":\n\t\tformat = api.FormatIIFE\n\tcase \"esm\":\n\t\tformat = api.FormatESModule\n\tcase \"cjs\":\n\t\tformat = api.FormatCommonJS\n\tdefault:\n\t\terr = fmt.Errorf(\"unsupported script output format: %q\", opts.Format)\n\t\treturn\n\t}\n\n\tvar jsx api.JSX\n\tswitch opts.JSX {\n\tcase \"\", \"transform\":\n\t\tjsx = api.JSXTransform\n\tcase \"preserve\":\n\t\tjsx = api.JSXPreserve\n\tcase \"automatic\":\n\t\tjsx = api.JSXAutomatic\n\tdefault:\n\t\terr = fmt.Errorf(\"unsupported jsx type: %q\", opts.JSX)\n\t\treturn\n\t}\n\n\tvar platform api.Platform\n\tswitch opts.Platform {","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/internal/js/esbuild/options.go#L336-L372","documentation":"Hugo maps the user-supplied `format` option to esbuild's output format when compiling JS via `js.Build`/`js.Batch`. Only `iife` (default when empty), `esm`, and `cjs` are accepted; any other string hits the default switch case in `toBuildOptions` and aborts option compilation with this error.","triggerScenarios":"Calling `resources.Get \"index.js\" | js.Build (dict \"format\" \"umd\")` or any format value other than \"\", \"iife\", \"esm\", \"cjs\" in the options dict passed to js.Build, or in a batch group's script options / config.","commonSituations":"Typos like \"es6\", \"module\", or \"commonjs\" instead of \"cjs\"; copying webpack/rollup config values (\"umd\", \"amd\") that esbuild-in-Hugo doesn't support; templating the format from site params where the param is unset to an unexpected value.","solutions":["Change the `format` option in your js.Build/js.Batch call to one of \"iife\", \"esm\", or \"cjs\".","Remove the option entirely to get the default IIFE output.","If the value comes from site params, verify the param spelling and value in hugo.toml/yaml."],"exampleFix":"{{/* before */}}\n{{ $js := resources.Get \"main.js\" | js.Build (dict \"format\" \"module\") }}\n{{/* after */}}\n{{ $js := resources.Get \"main.js\" | js.Build (dict \"format\" \"esm\") }}","handlingStrategy":"validation","validationCode":"// Go caller / template author: check format before invoking js.Build\nvalidFormats := map[string]bool{\"iife\": true, \"cjs\": true, \"esm\": true}\nif !validFormats[opts.Format] {\n    return fmt.Errorf(\"invalid script output format %q; must be one of iife, cjs, esm\", opts.Format)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only pass format values documented for js.Build: iife, cjs, or esm.","Centralize resource options in site config/data so the format string is set in one place, not per-template.","Run hugo locally after changing JS build options; these errors surface at build time, not runtime."],"tags":["hugo","esbuild","js-build","config","template-options"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}