clockworklabs/SpacetimeDB · error · anyhow::Error

Path {} exists but is not a directory. A new SpacetimeDB pro

Error message

Path {} exists but is not a directory. A new SpacetimeDB project must be initialized in an empty directory.

What it means

init scaffolds into a target directory and refuses to clobber existing state; the pre-flight check `ensure_empty_directory` first verifies that, when the target path exists, it is a directory. A regular file (or symlink to a file) at that path aborts init immediately with this error.

Source

Thrown at crates/cli/src/subcommands/init.rs:781

    }

    Ok(TemplateConfig {
        project_name,
        project_path,
        template_type: TemplateType::Empty,
        server_lang: parse_server_lang(&server_lang_str)?,
        client_lang: None,
        github_repo: None,
        template_def: None,
        use_local: true,
        native_aot: false,
    })
}

pub fn ensure_empty_directory(_project_name: &str, project_path: &Path, is_server_only: bool) -> anyhow::Result<()> {
    if project_path.exists() {
        if !project_path.is_dir() {
            anyhow::bail!(
                "Path {} exists but is not a directory. A new SpacetimeDB project must be initialized in an empty directory.",
                project_path.display()
            );
        }

        if std::fs::read_dir(project_path).unwrap().count() > 0 {
            if is_server_only {
                let server_dir = project_path.join("spacetimedb");
                if server_dir.exists() && std::fs::read_dir(server_dir).unwrap().count() > 0 {
                    anyhow::bail!(
                        "A SpacetimeDB module already exists in the target directory: {}",
                        project_path.display()
                    );
                }
            } else {
                anyhow::bail!(
                    "Cannot create new SpacetimeDB project in non-empty directory: {}",
                    project_path.display()

View on GitHub (pinned to 524b4487d9)

Solutions

  1. Move or delete the file occupying that path
  2. Point init at a different path via `--project-path`
  3. Re-check the project name — the path is derived from its slugified form

Example fix

# before — ./my-app is a regular file
spacetime init --non-interactive --project-name my-app --lang rust

# after
rm ./my-app
spacetime init --non-interactive --project-name my-app --lang rust
Defensive patterns

Strategy: validation

Validate before calling

# Pre-flight the target path:
TARGET="${PROJECT_PATH:-./$(echo "$PROJECT_NAME" | tr '[:upper:]' '[:lower:]' | tr -c 'a-z0-9-' '-')}"
if [[ -e "$TARGET" && ! -d "$TARGET" ]]; then
  echo "refusing to init: $TARGET exists and is not a directory" >&2; exit 2
fi
spacetime init --non-interactive --project-name "$PROJECT_NAME" --lang rust

Prevention

When it happens

Trigger: `spacetime init` where the resolved project path (from `--project-path` or the derived `./<name>` location) is occupied by a regular file; a stale artifact with the same name as the intended directory.

Common situations: A previous command left a file named like the project; name collisions between the slugified project name and existing files; wrong `--project-path` pointing at a file.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16). Data as JSON: /api/errors/6f182f4a01f07224. Report an issue: GitHub.