clockworklabs/SpacetimeDB · error · anyhow::Error

Project initialization did not create spacetimedb directory

Error message

Project initialization did not create spacetimedb directory

What it means

After `spacetime dev` scaffolds a new project (the init flow), the code asserts that the expected spacetimedb module directory now exists. If the initializer reported success but did not create the directory, dev aborts with this message instead of continuing against a missing module.

Solutions

  1. Scroll up and inspect the init output for the real failure
  2. Create the directory manually (`mkdir spacetimedb`) and re-run
  3. If using a custom template, fix it so it actually creates the module directory

Example fix

# before
spacetime dev --init
# error: Project initialization did not create spacetimedb directory

# after
mkdir spacetimedb
spacetime dev
Defensive patterns

Strategy: validation

Validate before calling

// after running init, verify the scaffold actually produced the module dir
init.execute()?;
let dir = project_dir.join("spacetimedb");
anyhow::ensure!(dir.exists(), "init did not create {}", dir.display());

Prevention

When it happens

Trigger: A custom or modified template whose init step exits 0 without creating the spacetimedb directory; init that partially fails (e.g. clone succeeded but post-processing did not run).

Common situations: Custom project templates; filesystem permission problems silently swallowing the directory creation; init commands that skip module scaffolding.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@3653d2ed49 (2026-08-20). Data as JSON: /api/errors/9b9dde5a0b0c5349. Report an issue: GitHub.

Appendix: source

Thrown at crates/cli/src/subcommands/dev.rs:447

            // If the project was created in a subdirectory, hint the user to cd into it
            // and show useful CLI commands they can run from there.
            let current_dir = std::env::current_dir().context("Failed to get current directory")?;
            let display_path = strip_verbatim_prefix(&canonical_created_path);
            if display_path != current_dir {
                let rel_path = display_path.strip_prefix(&current_dir).unwrap_or(display_path);
                println!(
                    "\n{} To interact with your database, open a new terminal and run:",
                    "Tip:".yellow().bold(),
                );
                println!("  cd ./{}", rel_path.display());
                println!("  spacetime call add Alice");
                println!("  spacetime sql \"SELECT * FROM person\"");
                println!("  spacetime logs");
                println!();
            }

            if !spacetimedb_dir.exists() {
                anyhow::bail!("Project initialization did not create spacetimedb directory");
            }

            // Clear publish_configs so they're rebuilt after init with the correct
            // spacetimedb_dir. Without this, configs built before init contain the
            // pre-init (stale) module path and the block below would overwrite the
            // correctly-updated spacetimedb_dir.
            publish_configs.clear();
        } else {
            anyhow::bail!("Not in a SpacetimeDB project directory");
        }
    } else if args.get_one::<String>("template").is_some() {
        println!(
            "{}",
            "Warning: --template option is ignored because a SpacetimeDB project already exists.".yellow()
        );
    }

    if let Some(config) = publish_configs.first() {

View on GitHub (pinned to 3653d2ed49)