{"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":801,"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":783,"sourceCodeEnd":819,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/fdd647dfac506d0967cc4492e9fce380706c94cb/crates/cli/src/subcommands/init.rs#L783-L819","documentation":"`spacetime init PATH` refuses to scaffold into a directory that already contains files, unless `--server-only` is used (in which case only the `spacetimedb/` subdirectory must be absent/empty). This guard prevents overwriting existing work with template files.","triggerScenarios":"Running `spacetime init .` in a repo that already has a README, .git, or any file; running init twice into the same directory; pointing PATH at a folder with editor/OS droppings like .DS_Store.","commonSituations":"Trying to add SpacetimeDB to an existing project in place; retrying an init that half-completed; scaffolding inside a git checkout.","solutions":["Init into a fresh empty directory and copy files in afterwards","Move or delete the existing contents (`ls -la` to catch hidden files like .git and .DS_Store)","If you only want the module, use `spacetime init PATH --server-only` into a dir where `spacetimedb/` is empty or missing","For adding SpacetimeDB to an existing repo, scaffold elsewhere and merge manually"],"exampleFix":"# before\nspacetime init .   # fails: directory not empty\n# after\nspacetime init my-new-project\ncd my-new-project","handlingStrategy":"validation","validationCode":"# only init when the target is empty (hidden files included)\n[ -z \"$(ls -A \"$DIR\" 2>/dev/null)\" ] && spacetime init \"$DIR\" || echo 'dir not empty'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always scaffold into a brand-new directory name","Remember `--server-only` tolerates a non-empty root as long as spacetimedb/ is empty"],"tags":["spacetime-init","filesystem","cli","scaffolding"],"backgroundTag":"directory-not-empty","analyzedSha":"fdd647dfac506d0967cc4492e9fce380706c94cb","analyzedAt":"2026-08-20T06:08:37.179Z","contentChangedAt":"2026-08-20T06:08:37.179Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}