DioxusLabs/dioxus · error · anyhow::Error

Destination directory '{}' already exists

Error message

Destination directory '{}' already exists

What it means

Destination guard in copy_component_files (called from add_component): before copying a component's files, the code checks whether the destination directory already exists and — unless the configured ComponentExistsBehavior says to overwrite or silently skip — bails. The input at fault is the destination path, which would clobber pre-existing project files.

Source

Thrown at packages/cli/src/cli/component.rs:652

    dest: &Path,
    exclude: &[String],
    behavior: ComponentExistsBehavior,
) -> Result<bool> {
    async fn read_dir_paths(src: &Path) -> Result<Vec<PathBuf>> {
        let mut entries = tokio::fs::read_dir(src).await?;
        let mut paths = vec![];
        while let Some(entry) = entries.next_entry().await? {
            paths.push(entry.path());
        }
        Ok(paths)
    }

    // If the directory already exists, return an error, return silently or overwrite it depending on the behavior
    if dest.exists() {
        match behavior {
            // The default behavior is to return an error
            ComponentExistsBehavior::Error => {
                bail!("Destination directory '{}' already exists", dest.display());
            }
            // For dependencies, we return early
            ComponentExistsBehavior::Return => {
                debug!(
                    "Destination directory '{}' already exists, returning early",
                    dest.display()
                );
                return Ok(false);
            }
            // If the force flag is set, we overwrite the existing component
            ComponentExistsBehavior::Overwrite => {
                debug!(
                    "Destination directory '{}' already exists, overwriting",
                    dest.display()
                );
                tokio::fs::remove_dir_all(dest).await?;
            }
        }

View on GitHub (pinned to 24f6a829df)

Solutions

  1. The destination directory already exists. Choose another name or remove the existing directory.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/cli/src/cli/component.rs:652 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of DioxusLabs/dioxus@24f6a829df (2026-08-23). Data as JSON: /api/errors/f4e9c24a7166325b. Report an issue: GitHub.