clockworklabs/SpacetimeDB · error · anyhow::Error

Not in a SpacetimeDB project directory

Error message

Not in a SpacetimeDB project directory

What it means

`spacetime dev` could not find a SpacetimeDB project: the current operation neither matched an existing project (no spacetimedb directory or module path) nor went through the init branch, so the command refuses to continue. It is a 'you are in the wrong place' error.

Solutions

  1. cd into the project directory or pass --project-path
  2. Scaffold first: use the init/template flow to create the project
  3. Provide --module-path pointing at your module directory

Example fix

# before
spacetime dev            # run from ~

# after
cd ~/projects/my-game
spacetime dev --project-path .
Defensive patterns

Strategy: validation

Validate before calling

// detect a SpacetimeDB project before running dev
fn is_project_dir(dir: &std::path::Path) -> bool {
    dir.join("spacetimedb").exists()
        || dir.join("spacetime.json").exists()
        || dir.join("spacetime.toml").exists()
}

Prevention

When it happens

Trigger: Running `spacetime dev` from a directory that has no spacetimedb/ dir, no module-path configuration, and no spacetime.json, without --project-path or --module-path.

Common situations: Wrong terminal or cwd; running from the repo root instead of the module directory; cloning a project and running dev before scaffolding.

Related errors


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

Appendix: source

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

                );
                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() {
        // if we have publish configs and we're past spacetimedb_dir manipulation,
        // we should set spacetimedb_dir to the path of the first config as this will be
        // later used for next steps
        if let Some(path) = config
            .get_one::<PathBuf>("module_path")
            .context("failed to read module_path from config")?
        {
            spacetimedb_dir = if path.is_absolute() {
                path

View on GitHub (pinned to 3653d2ed49)