denoland/deno · error

Refusing to delete existing directory '{}': it was not creat

Error message

Refusing to delete existing directory '{}': it was not created by `deno desktop`. The app name was inferred from the entrypoint or the project directory and collided with this directory. Pass --output to choose a different name, or remove the directory yourself if it is a leftover from an older build.

What it means

Thrown by reserve_app_dir when the destination path already exists as a NON-empty directory that the tool cannot prove it created: it contains neither the APP_DIR_MARKER file `.deno-desktop-app` (at the root, or under Contents/Resources for a macOS .app) nor is it empty. Because the app name is inferred from the entrypoint/project directory, this collision is usually with YOUR data, and the tool refuses to delete it (data-safety fix for issue #35510).

Source

Thrown at cli/tools/desktop.rs:1548

       Pass --output to choose a different name.",
      app_dir.display()
    );
  }

  // A bundle we generated carries the marker (at the directory root for
  // Linux/Windows, or under `Contents/Resources` for a macOS `.app`).
  let is_ours = app_dir.join(APP_DIR_MARKER).exists()
    || app_dir
      .join("Contents")
      .join("Resources")
      .join(APP_DIR_MARKER)
      .exists();
  let is_empty = std::fs::read_dir(app_dir)
    .map(|mut entries| entries.next().is_none())
    .unwrap_or(false);

  if !is_ours && !is_empty {
    bail!(
      "Refusing to delete existing directory '{}': it was not created by \
       `deno desktop`. The app name was inferred from the entrypoint or the \
       project directory and collided with this directory. Pass --output to \
       choose a different name, or remove the directory yourself if it is a \
       leftover from an older build.",
      app_dir.display()
    );
  }

  std::fs::remove_dir_all(app_dir).with_context(|| {
    format!("failed to clear app directory {}", app_dir.display())
  })?;
  Ok(())
}

/// Package a compiled desktop dylib into a platform-specific app bundle.
async fn package_desktop_app(
  dylib_path: &Path,

View on GitHub (pinned to f7822238ca)

Solutions

  1. Pass `--output` with a distinct path: `deno desktop --output dist/MyApp-deno main.ts`.
  2. If the directory is a leftover from an older build, verify its contents and remove it yourself: `rm -rf <path>`.
  3. Otherwise keep your data and change the inferred name (rename entrypoint/project dir) so future builds do not collide.

Example fix

# before (build/ holds unrelated artifacts)
deno desktop --output build main.ts

# after
deno desktop --output dist/app main.ts   # or: rm -rf build  (if it is a stale deno-desktop bundle)
Defensive patterns

Strategy: validation

Validate before calling

# bash: only reuse an existing dir if it is a deno-desktop bundle or empty
OUT="dist/MyApp"
if [[ -d "$OUT" ]]; then
  if [[ ! -f "$OUT/.deno-desktop-app" && ! -f "$OUT/Contents/Resources/.deno-desktop-app" ]] \
     && [[ -n "$(ls -A "$OUT")" ]]; then
    echo "$OUT holds non-deno data; pick another --output" >&2; exit 1
  fi
fi
deno desktop --output "$OUT" main.ts

Prevention

When it happens

Trigger: `deno desktop main.ts` where the inferred name matches an existing project folder (e.g. entrypoint `app/main.ts` with a sibling `app/` dir full of sources); `--output build` where `build/` already holds other artifacts; a bundle produced by an OLDER Deno version that predates the marker file.

Common situations: Entrypoint stem equals a real source directory (main/main.ts next to main/); output dir reused across tools (webpack build/, Xcode DerivedData); upgrading from a pre-marker deno desktop whose old bundles lack `.deno-desktop-app` so they look like foreign data.

Related errors


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