clockworklabs/SpacetimeDB · error · anyhow::Error

Not in a SpacetimeDB project directory

Error message

Not in a SpacetimeDB project directory

What it means

`spacetime dev` bails with this when it needs an existing project (no init was performed this run) but the current layout is not recognized as a SpacetimeDB project — i.e. no `spacetimedb` directory and no usable `spacetime.json`/config was found at the resolved project path.

Source

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

                );
                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 524b4487d9)

Solutions

  1. cd into the directory containing `spacetime.json` (or the `spacetimedb/` module folder) and re-run
  2. Point at the right place: `spacetime dev --project-path path/to/project`
  3. If starting fresh, run `spacetime init` (or let `spacetime dev` init) to scaffold a project first
  4. Verify `spacetime.json` exists, is valid JSON, and sits at the project root you targeted

Example fix

# before (in ~)
spacetime dev
# after
spacetime dev --project-path ~/code/my-spdb-app
Defensive patterns

Strategy: validation

Validate before calling

# Guard the invocation on project markers
if [ ! -f spacetime.json ] && [ ! -d spacetimedb ]; then
  echo "not a SpacetimeDB project"; exit 1
fi
spacetime dev

Prevention

When it happens

Trigger: Running `spacetime dev` in an unrelated directory; `--project-path` pointing at a folder without `spacetime.json` or `spacetimedb/`; config file exists but is empty/invalid so it does not count as a project.

Common situations: Wrong terminal/cwd (typing `spacetime dev` in `~` or a client repo); typos in `--project-path`; renamed or deleted `spacetime.json`; nested monorepo where the project root differs from cwd.

Related errors


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