{"record":{"id":"6f1b34ae62266e8d","repo":"denoland/deno","slug":"refusing-to-delete-existing-directory-it-was","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/tools/desktop.rs","lineNumber":1548,"sourceCode":"       Pass --output to choose a different name.\",\n      app_dir.display()\n    );\n  }\n\n  // A bundle we generated carries the marker (at the directory root for\n  // Linux/Windows, or under `Contents/Resources` for a macOS `.app`).\n  let is_ours = app_dir.join(APP_DIR_MARKER).exists()\n    || app_dir\n      .join(\"Contents\")\n      .join(\"Resources\")\n      .join(APP_DIR_MARKER)\n      .exists();\n  let is_empty = std::fs::read_dir(app_dir)\n    .map(|mut entries| entries.next().is_none())\n    .unwrap_or(false);\n\n  if !is_ours && !is_empty {\n    bail!(\n      \"Refusing to delete existing directory '{}': it was not created by \\\n       `deno desktop`. The app name was inferred from the entrypoint or the \\\n       project directory and collided with this directory. Pass --output to \\\n       choose a different name, or remove the directory yourself if it is a \\\n       leftover from an older build.\",\n      app_dir.display()\n    );\n  }\n\n  std::fs::remove_dir_all(app_dir).with_context(|| {\n    format!(\"failed to clear app directory {}\", app_dir.display())\n  })?;\n  Ok(())\n}\n\n/// Package a compiled desktop dylib into a platform-specific app bundle.\nasync fn package_desktop_app(\n  dylib_path: &Path,","sourceCodeStart":1530,"sourceCodeEnd":1566,"githubUrl":"https://github.com/denoland/deno/blob/f7822238cab635a3a19f99f493f675fa81a7f9d8/cli/tools/desktop.rs#L1530-L1566","documentation":"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).","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Pass `--output` with a distinct path: `deno desktop --output dist/MyApp-deno main.ts`.","If the directory is a leftover from an older build, verify its contents and remove it yourself: `rm -rf <path>`.","Otherwise keep your data and change the inferred name (rename entrypoint/project dir) so future builds do not collide."],"exampleFix":"# before (build/ holds unrelated artifacts)\ndeno desktop --output build main.ts\n\n# after\ndeno desktop --output dist/app main.ts   # or: rm -rf build  (if it is a stale deno-desktop bundle)","handlingStrategy":"validation","validationCode":"# bash: only reuse an existing dir if it is a deno-desktop bundle or empty\nOUT=\"dist/MyApp\"\nif [[ -d \"$OUT\" ]]; then\n  if [[ ! -f \"$OUT/.deno-desktop-app\" && ! -f \"$OUT/Contents/Resources/.deno-desktop-app\" ]] \\\n     && [[ -n \"$(ls -A \"$OUT\")\" ]]; then\n    echo \"$OUT holds non-deno data; pick another --output\" >&2; exit 1\n  fi\nfi\ndeno desktop --output \"$OUT\" main.ts","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never point --output at a directory with unrelated content; use a dedicated dist path.","Avoid entrypoint/project names that collide with existing source folders (main/main.ts beside main/).","Bundles from very old Deno versions lack the .deno-desktop-app marker — delete them manually once, then future builds are recognized."],"tags":["desktop","output-path","directory-collision","data-safety","cli"],"backgroundTag":"output-path-collision","analyzedSha":"f7822238cab635a3a19f99f493f675fa81a7f9d8","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}