clockworklabs/SpacetimeDB · error · anyhow::Error
Cannot create new SpacetimeDB project in non-empty directory
Error message
Cannot create new SpacetimeDB project in non-empty directory: {} What it means
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/`.
Source
Thrown at crates/cli/src/subcommands/init.rs:797
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()
);
}
}
} else {
fs::create_dir_all(project_path).context("Failed to create directory")?;
}
Ok(())
}
async fn get_template_config_interactive(
options: &InitOptions,
project_name: String,
project_path: PathBuf,
) -> anyhow::Result<TemplateConfig> {
let theme = ColorfulTheme::default();
View on GitHub (pinned to 524b4487d9)
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
Example fix
# before — ./my-app already contains files spacetime init --non-interactive --project-name my-app --lang rust # after — either clean it rm -rf my-app && spacetime init --non-interactive --project-name my-app --lang rust # after — or only add a module to the existing project spacetime init --non-interactive --project-name my-app --lang rust --server-only
Defensive patterns
Strategy: validation
Validate before calling
# Full-init pre-flight: target must be empty, including dotfiles:
TARGET="${PROJECT_PATH:-./my-app}"
if [[ -e "$TARGET" ]]; then
[[ -d "$TARGET" ]] || { echo "$TARGET is a file" >&2; exit 2; }
[[ -z $(ls -A "$TARGET") ]] || { echo "$TARGET is not empty" >&2; exit 2; }
fi
spacetime init --non-interactive --project-name my-app --lang rust Prevention
- 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
When it happens
Trigger: `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.
Common situations: 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.
Related errors
- Path {} exists but is not a directory. A new SpacetimeDB pro
- A SpacetimeDB module already exists in the target directory:
- Fatal Error: path {} exists but is not a directory.
- Fatal Error: path {} does not exist.
- Project initialization did not create spacetimedb directory
AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16).
Data as JSON: /api/errors/f51ec414ccf3f84b.
Report an issue: GitHub.