denoland/deno · error
Unsupported media type for snapshotting {media_type:?} for f
Error message
Unsupported media type for snapshotting {media_type:?} for file {} What it means
When preparing startup snapshot inputs, runtime/transpile.rs accepts only TypeScript, JavaScript, and Mjs sources. Any other media type (JSX, TSX, JSON, CSS, etc.) reaches a panic because the snapshot transpile path has no emitter for it.
Source
Thrown at runtime/transpile.rs:87
let source = maybe_substitute_node_version(&name_string, source);
// Always transpile `node:` built-in modules, since they might be TypeScript.
let media_type = if name.starts_with("node:") {
MediaType::TypeScript
} else {
MediaType::from_path(Path::new(&name))
};
match media_type {
MediaType::TypeScript => {}
MediaType::JavaScript | MediaType::Mjs => {
if minify {
let source =
minify_source_with_rolldown(&name_string, source.as_ref())?;
return Ok((source.into(), None));
}
return Ok((source, None));
}
_ => panic!(
"Unsupported media type for snapshotting {media_type:?} for file {}",
name
),
}
let parsed = deno_ast::parse_module(ParseParams {
specifier: deno_core::url::Url::parse(&name).unwrap(),
text: source.into(),
media_type,
capture_tokens: false,
scope_analysis: false,
maybe_syntax: None,
})
.map_err(|e| JsErrorBox::from_err(JsParseDiagnostic(e)))?;
let transpiled_source = parsed
.transpile(
&deno_ast::TranspileOptions {
imports_not_used_as_values: deno_ast::ImportsNotUsedAsValues::Remove,View on GitHub (pinned to 9ad36f7a2c)
Solutions
- Filter snapshot inputs to .js/.mjs/.ts before invoking the transpile step
- Pre-transpile JSX/TSX to plain JS yourself if those files must be snapshotted
- Point the snapshot build at an explicit file list instead of a directory glob
Example fix
// before
let files = std::fs::read_dir(dir)?; // picks up app.jsx -> panic
// after
let files = std::fs::read_dir(dir)?.filter(|e| {
matches!(
e.as_ref().ok().and_then(|e| e.path().extension().and_then(|s| s.to_str())),
Some("js") | Some("mjs") | Some("ts")
)
}); Defensive patterns
Strategy: validation
Validate before calling
fn snapshottable(path: &std::path::Path) -> bool {
matches!(
path.extension().and_then(|s| s.to_str()),
Some("js") | Some("mjs") | Some("ts")
)
}
for path in inputs {
if !snapshottable(&path) {
return Err(format!("{} is not snapshottable; pre-transpile or exclude it", path.display()));
}
} Prevention
- Use an explicit allowlist of input files for snapshot builds instead of directory globs
- Pre-transpile JSX/TSX to JS before feeding the snapshot step
- Fail on unknown extensions during build configuration, not inside the transpile path
When it happens
Trigger: Feeding a .jsx, .tsx, .json, .css, or other non-JS/TS file into snapshot/transpile input - e.g. a custom snapshot build script that globs a directory containing mixed file types.
Common situations: Custom embedders building snapshots with broad file globs; workspaces where JSX files sit next to JS; bundler outputs containing unexpected extensions.
Related errors
- Unexpected media type {media_type} for {specifier}
- Attempted to read snapshot data out of range: {id} (of {})
- Attempted to read the snapshot data at index {id} twice
- Invalid data type at index {id}, expected '{}'
- Bootstrap exception: {error}
AI-assisted analysis of denoland/deno@9ad36f7a2c (2026-08-20).
Data as JSON: /api/errors/631bba96a3666daa.
Report an issue: GitHub.