{"record":{"id":"49c27814bdaf688c","repo":"denoland/deno","slug":"unsupported-media-type-for","errorCode":null,"errorMessage":"unsupported media type {} for {}","messagePattern":"unsupported media type (.+?) for (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"libs/eszip/v2.rs","lineNumber":1438,"sourceCode":"                }\n                _ => Cow::Borrowed(emit_options),\n              };\n              let emit = parsed_source\n                .transpile(\n                  transpile_options,\n                  &TranspileModuleOptions {\n                    module_kind: module_kind_provider.module_kind(module),\n                  },\n                  &emit_options,\n                )?\n                .into_source();\n              source = emit.text.into_bytes().into();\n              source_map = Arc::from(\n                emit.source_map.map(|s| s.into_bytes()).unwrap_or_default(),\n              );\n            }\n            _ => {\n              return Err(anyhow::anyhow!(\n                \"unsupported media type {} for {}\",\n                module.media_type,\n                visited.specifier()\n              ));\n            }\n          };\n\n          let eszip_module = EszipV2Module::Module {\n            kind: ModuleKind::JavaScript,\n            source: EszipV2SourceSlot::Ready(source),\n            source_map: EszipV2SourceSlot::Ready(source_map),\n          };\n          modules.insert(specifier_key.into_owned(), eszip_module);\n\n          Ok(Some(Box::new(module.dependencies.values().filter_map(\n            |dependency| {\n              Some(ToVisit::Module {\n                specifier: dependency.get_code()?,","sourceCodeStart":1420,"sourceCodeEnd":1456,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/libs/eszip/v2.rs#L1420-L1456","documentation":"When eszip stores a module in its JavaScript source slot, it handles a fixed set of media types (JS/JSX served as-is, TS/TSX transpiled with the given emit options). If the module's media type falls into the catch-all arm, the build rejects it with 'unsupported media type <type> for <specifier>' — the module kind cannot be represented as embedded JS source.","triggerScenarios":"A static import resolving to a file with an extension Deno maps to a non-code type (e.g. .wasm, .html, .sql, .md or an unknown/extensionless type under certain media-type providers) being visited as a regular module; a server serving JS content with a Content-Type that deno_graph classifies as something else.","commonSituations":"Importing asset files as if they were JS modules (works in bundlers with asset loaders, not in Deno's eszip path); extensionless files or misconfigured media types on dev servers; older Deno versions classifying some extensions differently than the current runtime.","solutions":["Import real JS/TS modules; load assets with Deno.readFile/inline bytes instead of `import`","Give the file a .js/.ts (or .mjs/.mts) extension so it maps to a supported media type","For local dev servers, send correct Content-Type (text/javascript or application/typescript) for module responses","If you need Wasm, use WebAssembly APIs / a loader path that stores it as a Wasm module rather than a JS-source slot"],"exampleFix":"// before\nimport shaderSrc from \"./shader.wasm\";  // unsupported media type Wasm\n\n// after\nconst shaderBytes = await Deno.readFile(new URL(\"./shader.wasm\", import.meta.url));","handlingStrategy":"validation","validationCode":"// Reject non-code imports before building\nconst CODE_EXT = /\\.(m?jsx?|m?tsx?|json|jsonc)$/;\nexport function assertImportable(specifier: string) {\n  if (!CODE_EXT.test(new URL(specifier, import.meta.url).pathname)) {\n    throw new Error(`Refusing to import non-code asset as module: ${specifier}`);\n  }\n}","typeGuard":"function isEmbeddableMediaType(path: string): boolean {\n  return /\\.(m?jsx?|m?tsx?|json|jsonc)$/i.test(path);\n}","tryCatchPattern":"const { success, stderr } = await new Deno.Command(\"deno\", { args: [\"compile\", \"src/mod.ts\"] }).output();\nconst err = new TextDecoder().decode(stderr);\nconst m = err.match(/unsupported media type (\\S+) for (\\S+)/);\nif (!success && m) switchToAssetLoader(m[2]); // readFile instead of import","preventionTips":["Load binary/asset files with Deno.readFile, never `import`","Give modules recognized extensions (.ts/.js); avoid extensionless imports","Serve correct Content-Type from local dev servers feeding deno"],"tags":["eszip","media-type","compile","module-graph","bundling"],"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-23T08:17:48.524Z"}