{"record":{"id":"4bb195c2dfee505f","repo":"denoland/deno","slug":"unexpected-media-type-media-type-for-specifier","errorCode":null,"errorMessage":"Unexpected media type {media_type} for {specifier}","messagePattern":"Unexpected media type (.+?) for (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"libs/resolver/loader/module_loader.rs","lineNumber":627,"sourceCode":"            MediaType::TypeScript\n            | MediaType::Mts\n            | MediaType::Jsx\n            | MediaType::Tsx => {\n              return Ok(Some(CodeOrDeferredEmit::DeferredEmit {\n                specifier,\n                media_type: *media_type,\n                source: &source.text,\n              }));\n            }\n            MediaType::Css\n            | MediaType::Html\n            | MediaType::Jsonc\n            | MediaType::Json5\n            | MediaType::Markdown\n            | MediaType::Sql\n            | MediaType::Wasm\n            | MediaType::SourceMap => {\n              panic!(\"Unexpected media type {media_type} for {specifier}\")\n            }\n          };\n\n          // at this point, we no longer need the parsed source in memory, so free it\n          self.parsed_source_cache.free(specifier);\n\n          Ok(Some(CodeOrDeferredEmit::Source(LoadedModule {\n            source: LoadedModuleSource::ArcStr(code),\n            specifier: Cow::Borrowed(specifier),\n            media_type: *media_type,\n          })))\n        }\n      },\n      Some(deno_graph::Module::Wasm(WasmModule {\n        source, specifier, ..\n      })) => Ok(Some(CodeOrDeferredEmit::Source(LoadedModule {\n        source: LoadedModuleSource::ArcBytes(source.clone()),\n        specifier: Cow::Borrowed(specifier),","sourceCodeStart":609,"sourceCodeEnd":645,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/libs/resolver/loader/module_loader.rs#L609-L645","documentation":"The graph-based module loader in libs/resolver hands sources to the runtime only for media types it can emit as JavaScript. When a module resolves to Css, Html, Jsonc, Json5, Markdown, Sql, Wasm, or SourceMap on this path, it panics because no JS emit exists for that type.","triggerScenarios":"Importing a .css, .html, .jsonc, .json5, .md, .sql, or .wasm file through a loader configuration that expects JS source output, without the asset/transpile pipeline the Deno CLI normally runs.","commonSituations":"Porting web code that imports stylesheets or markdown; importing JSON5/JSONC configs as modules; embedders reusing the resolver loader without configuring transpilation.","solutions":["Load the asset with a read API instead of an ESM import","Import a supported module type (JS/TS/JSON as allowed by your runtime configuration)","Configure the transpile or asset pipeline for that media type before this loader path runs","Check the resolved MediaType up front and reject non-JS/TS types with a real error"],"exampleFix":"// before\nimport styles from \"./styles.css\"; // panics: Unexpected media type Css\n\n// after\nconst styles = await Deno.readTextFile(new URL(\"./styles.css\", import.meta.url));","handlingStrategy":"validation","validationCode":"use deno_ast::MediaType;\n\nfn unusable_as_module_source(mt: MediaType) -> bool {\n  matches!(\n    mt,\n    MediaType::Css | MediaType::Html | MediaType::Jsonc | MediaType::Json5\n      | MediaType::Markdown | MediaType::Sql | MediaType::Wasm | MediaType::SourceMap\n  )\n}\n\n// reject before the loader panics\nif unusable_as_module_source(media_type) {\n  return Err(format!(\"{specifier} cannot be loaded as a module source\"));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep ESM imports limited to JS/TS-family files; load assets with read APIs","In embedders, resolve the MediaType and reject unsupported types with a real error before handing off to the loader","Lint the codebase for imports of .css/.md/.sql/.html extensions in CI"],"tags":["media-type","module-loading","import","asset-imports","panic"],"backgroundTag":"unsupported-media-type","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}