denoland/deno · error

Could not compile to file '{}' because the file already exis

Error message

Could not compile to file '{}' because the file already exists and cannot be overwritten. Please delete the existing file or use the `--output <file-path>` flag to provide an alternative name.

What it means

Error "Could not compile to file '{}' because the file already exists and cannot be overwritten. Please delete the existing file or use the `--output <file-path>` flag to provide an alternative name." thrown in denoland/deno.

Source

Thrown at cli/tools/compile.rs:1048

/// is not already standalone binary it will return error instead.
fn validate_output_path(output_path: &Path) -> Result<(), AnyError> {
  if output_path.exists() {
    // If the output is a directory, throw error
    if output_path.is_dir() {
      bail!(
        concat!(
          "Could not compile to file '{}' because a directory exists with ",
          "the same name. You can use the `--output <file-path>` flag to ",
          "provide an alternative name."
        ),
        output_path.display()
      );
    }

    // Make sure we don't overwrite any file not created by Deno compiler because
    // this filename is chosen automatically in some cases.
    if !is_standalone_binary(output_path) {
      bail!(
        concat!(
          "Could not compile to file '{}' because the file already exists ",
          "and cannot be overwritten. Please delete the existing file or ",
          "use the `--output <file-path>` flag to provide an alternative name."
        ),
        output_path.display()
      );
    }

    // Remove file if it was indeed a deno compiled binary, to avoid corruption
    // (see https://github.com/denoland/deno/issues/10310)
    std::fs::remove_file(output_path)?;
  } else {
    let output_base = &output_path.parent().unwrap();
    if output_base.exists() && output_base.is_file() {
      bail!(
        concat!(
          "Could not compile to file '{}' because its parent directory ",

View on GitHub (pinned to f7822238ca)

When it happens

Trigger: Thrown at cli/tools/compile.rs:1048 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of denoland/deno@f7822238ca (2026-08-20). Data as JSON: /api/errors/ae7e8005dc828a19. Report an issue: GitHub.