{"id":"63aa131d562270f1","repo":"gohugoio/hugo","slug":"unsupported-media-type-q","errorCode":null,"errorMessage":"unsupported Media Type: %q","messagePattern":"unsupported Media Type: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/js/esbuild/options.go","lineNumber":340,"sourceCode":"\tmediaType := opts.MediaType\n\tif mediaType.IsZero() {\n\t\tmediaType = media.Builtin.JavascriptType\n\t}\n\n\tvar loader api.Loader\n\tswitch mediaType.SubType {\n\tcase media.Builtin.JavascriptType.SubType:\n\t\tloader = api.LoaderJS\n\tcase media.Builtin.TypeScriptType.SubType:\n\t\tloader = api.LoaderTS\n\tcase media.Builtin.TSXType.SubType:\n\t\tloader = api.LoaderTSX\n\tcase media.Builtin.JSXType.SubType:\n\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","sourceCodeStart":322,"sourceCodeEnd":358,"githubUrl":"https://github.com/gohugoio/hugo/blob/8a468df065a75c1c7cf9f6850f32148746590ea5/internal/js/esbuild/options.go#L322-L358","documentation":"When picking the loader for the entry-point resource, Hugo switches on the resource's media type: JavaScript, TypeScript, TSX, JSX, and CSS map to the corresponding esbuild loader. Any other media type (e.g. text/html, image/png) can't be a js.Build entry point, so option compilation fails naming the media type.","triggerScenarios":"Piping a resource whose media type isn't JS/TS/TSX/JSX/CSS into `js.Build`, e.g. `resources.Get \"data.json\" | js.Build` or a file whose extension Hugo maps to an unknown/plain-text media type.","commonSituations":"Passing the wrong resource variable into js.Build; entry files with nonstandard extensions (.mjs/.cjs on older Hugo versions, or custom extensions) that don't resolve to a script media type; templated (.js.tmpl) sources not executed with resources.ExecuteAsTemplate first.","solutions":["Only pass script or CSS resources to js.Build — the entry point must be .js/.jsx/.ts/.tsx (or CSS for the CSS pipeline); import JSON from within your JS instead of building it directly.","Rename the entry file to a standard extension, or add a mediaTypes/suffixes config entry mapping your extension to a script media type.","If the source is templated, run resources.ExecuteAsTemplate to produce a .js resource before js.Build."],"exampleFix":"{{/* before */}}\n{{ $bundle := resources.Get \"data/config.json\" | js.Build }}\n{{/* after: import the JSON from the JS entry point */}}\n{{ $bundle := resources.Get \"js/main.js\" | js.Build }}\n// main.js\nimport config from '../data/config.json';","handlingStrategy":"validation","validationCode":"switch mediaType {\ncase \"text/javascript\", \"text/typescript\", \"text/tsx\", \"text/jsx\":\n    // ok\ndefault:\n    return fmt.Errorf(\"js.Build cannot process media type %q\", mediaType)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass only JS/TS/JSX/TSX resources to js.Build — give source files proper extensions so Hugo infers the right media type","If serving unusual extensions, register them under a supported media type in your config","Don't pipe CSS/JSON resources through js.Build; use the appropriate pipe (css.Sass, resources.Minify) instead"],"tags":["hugo","js-build","esbuild","media-types"],"analyzedSha":"8a468df065a75c1c7cf9f6850f32148746590ea5","analyzedAt":"2026-07-31T21:23:07.045Z","schemaVersion":2}