{"record":{"id":"f51ec414ccf3f84b","repo":"clockworklabs/SpacetimeDB","slug":"cannot-create-new-spacetimedb-project-in-non-empty","errorCode":null,"errorMessage":"Cannot create new SpacetimeDB project in non-empty directory: {}","messagePattern":"Cannot create new SpacetimeDB project in non-empty directory: (.+?)","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/init.rs","lineNumber":797,"sourceCode":"    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()\n                );\n            }\n        }\n    } else {\n        fs::create_dir_all(project_path).context(\"Failed to create directory\")?;\n    }\n    Ok(())\n}\n\nasync fn get_template_config_interactive(\n    options: &InitOptions,\n    project_name: String,\n    project_path: PathBuf,\n) -> anyhow::Result<TemplateConfig> {\n    let theme = ColorfulTheme::default();\n","sourceCodeStart":779,"sourceCodeEnd":815,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/cli/src/subcommands/init.rs#L779-L815","documentation":"Full (client + server) init requires an empty target directory: any existing entry — including dotfiles like `.git` or `.DS_Store` — causes init to abort rather than risk overwriting. This is the non-server-only branch of the same `ensure_empty_directory` pre-flight check; server-only mode relaxes it by allowing content outside `spacetimedb/`.","triggerScenarios":"`spacetime init` where the resolved project path already contains anything at all; scaffolding into the current repo root; re-init over a previous (even failed) attempt; directories containing only hidden files.","commonSituations":"Retrying init after an interrupted run; wanting to add SpacetimeDB to an existing project (use --server-only instead); initialized git repos counted as non-empty.","solutions":["Init into a new, truly empty directory","Clean the directory including hidden files, then re-run","If you only need the server module added to an existing project, use `--server-only`","If you want pre-existing content as a starting point, clone a template repo with `--template owner/repo` instead"],"exampleFix":"# before — ./my-app already contains files\nspacetime init --non-interactive --project-name my-app --lang rust\n\n# after — either clean it\nrm -rf my-app && spacetime init --non-interactive --project-name my-app --lang rust\n\n# after — or only add a module to the existing project\nspacetime init --non-interactive --project-name my-app --lang rust --server-only","handlingStrategy":"validation","validationCode":"# Full-init pre-flight: target must be empty, including dotfiles:\nTARGET=\"${PROJECT_PATH:-./my-app}\"\nif [[ -e \"$TARGET\" ]]; then\n  [[ -d \"$TARGET\" ]] || { echo \"$TARGET is a file\" >&2; exit 2; }\n  [[ -z $(ls -A \"$TARGET\") ]] || { echo \"$TARGET is not empty\" >&2; exit 2; }\nfi\nspacetime init --non-interactive --project-name my-app --lang rust","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Scaffold into a fresh directory; init refuses non-empty targets to protect existing files","Remember hidden files (.git, .DS_Store) count as content","For existing projects, use --server-only or clone a template repo instead"],"tags":["init","directory-not-empty","filesystem","pre-flight-check"],"backgroundTag":"target-directory-not-empty","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}