denoland/deno · error

unsupported media type {} for {}

Error message

unsupported media type {} for {}

What it means

Inside the JS-module arm of eszip v2 creation, only JavaScript, Mjs, Jsx, TypeScript, Mts, Tsx, Dts and Dmts media types are handled (passthrough or transpile). A Js module with any other media type — Css, Wasm, Html, SourceMap, Unknown, Cjs — hits the catch-all arm and errors.

Source

Thrown at libs/eszip/v2.rs:1438

                }
                _ => Cow::Borrowed(emit_options),
              };
              let emit = parsed_source
                .transpile(
                  transpile_options,
                  &TranspileModuleOptions {
                    module_kind: module_kind_provider.module_kind(module),
                  },
                  &emit_options,
                )?
                .into_source();
              source = emit.text.into_bytes().into();
              source_map = Arc::from(
                emit.source_map.map(|s| s.into_bytes()).unwrap_or_default(),
              );
            }
            _ => {
              return Err(anyhow::anyhow!(
                "unsupported media type {} for {}",
                module.media_type,
                visited.specifier()
              ));
            }
          };

          let eszip_module = EszipV2Module::Module {
            kind: ModuleKind::JavaScript,
            source: EszipV2SourceSlot::Ready(source),
            source_map: EszipV2SourceSlot::Ready(source_map),
          };
          modules.insert(specifier_key.into_owned(), eszip_module);

          Ok(Some(Box::new(module.dependencies.values().filter_map(
            |dependency| {
              Some(ToVisit::Module {
                specifier: dependency.get_code()?,

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Remove direct imports of non-JS/TS assets from the entry graph (load CSS via link tags at runtime; load wasm with fetch + WebAssembly.instantiate)
  2. Rename files to supported extensions (.js/.mjs/.jsx/.ts/.mts/.tsx/.d.ts/.d.mts)
  3. Inspect the specifier named in the error to find which import produced the unsupported media type

Example fix

// before — CSS imported directly into the eszip-built graph
import "./styles.css";

// after — keep CSS out of the bundle graph; inject at runtime
const link = document.createElement("link");
link.rel = "stylesheet";
link.href = new URL("./styles.css", import.meta.url).href;
document.head.appendChild(link);
Defensive patterns

Strategy: validation

Validate before calling

use deno_graph::Module;

// reject graphs with unsupported media types before eszip creation
for module in graph.modules() {
  if let Module::Js(js) = module {
    let supported = matches!(
      js.media_type,
      deno_graph::MediaType::JavaScript
        | deno_graph::MediaType::Mjs
        | deno_graph::MediaType::Jsx
        | deno_graph::MediaType::TypeScript
        | deno_graph::MediaType::Mts
        | deno_graph::MediaType::Tsx
        | deno_graph::MediaType::Dts
        | deno_graph::MediaType::Dmts
    );
    if !supported {
      anyhow::bail!("unsupported media type {} for {}", js.media_type, js.specifier);
    }
  }
}

Type guard

fn is_eszip_supported(mt: deno_graph::MediaType) -> bool {
  matches!(
    mt,
    deno_graph::MediaType::JavaScript
      | deno_graph::MediaType::Mjs
      | deno_graph::MediaType::Jsx
      | deno_graph::MediaType::TypeScript
      | deno_graph::MediaType::Mts
      | deno_graph::MediaType::Tsx
      | deno_graph::MediaType::Dts
      | deno_graph::MediaType::Dmts
  )
}

Prevention

When it happens

Trigger: A module classified as JavaScript in the graph whose media type falls outside the supported set: importing .css/.wasm/.html/.cjs files, or files with unknown extensions that resolve as JS, into a graph fed to eszip.

Common situations: Bundling/compiling a project that imports stylesheets or wasm directly; renaming files to extensions deno_graph types as Unknown; .cjs entries in the graph.

Related errors


AI-assisted analysis of denoland/deno@89f33cbef2 (2026-08-16). Data as JSON: /api/errors/49c27814bdaf688c. Report an issue: GitHub.