{"record":{"id":"6f182f4a01f07224","repo":"clockworklabs/SpacetimeDB","slug":"path-exists-but-is-not-a-directory-a-new-space","errorCode":null,"errorMessage":"Path {} exists but is not a directory. A new SpacetimeDB project must be initialized in an empty directory.","messagePattern":"Path (.+?) exists but is not a directory\\. A new SpacetimeDB project must be initialized in an empty directory\\.","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/init.rs","lineNumber":781,"sourceCode":"    }\n\n    Ok(TemplateConfig {\n        project_name,\n        project_path,\n        template_type: TemplateType::Empty,\n        server_lang: parse_server_lang(&server_lang_str)?,\n        client_lang: None,\n        github_repo: None,\n        template_def: None,\n        use_local: true,\n        native_aot: false,\n    })\n}\n\npub fn ensure_empty_directory(_project_name: &str, project_path: &Path, is_server_only: bool) -> anyhow::Result<()> {\n    if project_path.exists() {\n        if !project_path.is_dir() {\n            anyhow::bail!(\n                \"Path {} exists but is not a directory. A new SpacetimeDB project must be initialized in an empty directory.\",\n                project_path.display()\n            );\n        }\n\n        if std::fs::read_dir(project_path).unwrap().count() > 0 {\n            if is_server_only {\n                let server_dir = project_path.join(\"spacetimedb\");\n                if server_dir.exists() && std::fs::read_dir(server_dir).unwrap().count() > 0 {\n                    anyhow::bail!(\n                        \"A SpacetimeDB module already exists in the target directory: {}\",\n                        project_path.display()\n                    );\n                }\n            } else {\n                anyhow::bail!(\n                    \"Cannot create new SpacetimeDB project in non-empty directory: {}\",\n                    project_path.display()","sourceCodeStart":763,"sourceCodeEnd":799,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/cli/src/subcommands/init.rs#L763-L799","documentation":"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.","triggerScenarios":"`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.","commonSituations":"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.","solutions":["Move or delete the file occupying that path","Point init at a different path via `--project-path`","Re-check the project name — the path is derived from its slugified form"],"exampleFix":"# before — ./my-app is a regular file\nspacetime init --non-interactive --project-name my-app --lang rust\n\n# after\nrm ./my-app\nspacetime init --non-interactive --project-name my-app --lang rust","handlingStrategy":"validation","validationCode":"# Pre-flight the target path:\nTARGET=\"${PROJECT_PATH:-./$(echo \"$PROJECT_NAME\" | tr '[:upper:]' '[:lower:]' | tr -c 'a-z0-9-' '-')}\"\nif [[ -e \"$TARGET\" && ! -d \"$TARGET\" ]]; then\n  echo \"refusing to init: $TARGET exists and is not a directory\" >&2; exit 2\nfi\nspacetime init --non-interactive --project-name \"$PROJECT_NAME\" --lang rust","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check for name collisions before init — the path is derived from the slugified project name","Let init create the directory itself rather than pre-creating files at the same path"],"tags":["init","filesystem","path","pre-flight-check"],"backgroundTag":"path-is-not-a-directory","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}