denoland/deno · error

Could not get emit filename.

Error message

Could not get emit filename.

What it means

EmitCache::set_cache derives a cache filename through the disk cache's URL-to-filename logic. For URL schemes it cannot name (anything outside wasm/http/https/data/blob/file, or a file/data URL that fails conversion) get_emit_filename returns None and the save aborts with this error — unless emit is disabled or the emit-failed flag is already raised, in which case the save is skipped.

Source

Thrown at libs/resolver/cache/emit.rs:108

      // assume the cache can't be written to and disable caching to it
      self.emit_failed_flag.raise();
    }
  }

  fn set_emit_code_result(
    &self,
    specifier: &Url,
    source_hash: u64,
    code: &[u8],
  ) -> Result<(), AnyError> {
    if matches!(self.mode, Mode::Disable) || self.emit_failed_flag.is_raised() {
      log::debug!("Skipped emit cache save of {}", specifier);
      return Ok(());
    }

    let emit_filename = self
      .get_emit_filename(specifier)
      .ok_or_else(|| anyhow!("Could not get emit filename."))?;
    let cache_data = self.file_serializer.serialize(code, source_hash);
    self.disk_cache.set(&emit_filename, &cache_data)?;

    Ok(())
  }

  fn get_emit_filename(&self, specifier: &Url) -> Option<PathBuf> {
    self
      .disk_cache
      .get_cache_filename_with_extension(specifier, "js")
  }
}

const LAST_LINE_PREFIX: &str = "\n// denoCacheMetadata=";

#[derive(Debug)]
struct EmitFileSerializer {
  cache_version: Cow<'static, str>,

View on GitHub (pinned to 89f33cbef2)

Solutions

  1. Restrict emit caching to module URLs with cacheable schemes (file/http/https/blob/wasm/data)
  2. Avoid importing via data: URLs in code whose emit will be cached
  3. If embedding EmitCache, pre-check scheme support and skip saving instead of erroring

Example fix

// before — save unconditionally, errors on non-cacheable schemes
emit_cache.set_cache(&specifier, source_hash, &code).await?;

// after — only save when the disk cache can name the specifier
let cacheable = matches!(
  specifier.scheme(),
  "file" | "http" | "https" | "data" | "blob" | "wasm"
);
if cacheable {
  emit_cache.set_cache(&specifier, source_hash, &code).await?;
}
Defensive patterns

Strategy: fallback

Validate before calling

// only attempt emit-cache saves for schemes the disk cache can name
fn is_emit_cacheable(specifier: &url::Url) -> bool {
  matches!(
    specifier.scheme(),
    "file" | "http" | "https" | "data" | "blob" | "wasm"
  )
}

Prevention

When it happens

Trigger: Saving transpile emit for a specifier whose scheme the disk cache cannot map to a filename: npm:, jsr: or node: specifiers routed through EmitCache, or a data: URL whose contents url_to_filename rejects.

Common situations: Custom loaders/resolvers surfacing exotic schemes into the emit pipeline; very long data: URL imports; embedders reusing EmitCache outside the CLI's normal file/http flow.

Related errors


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