clockworklabs/SpacetimeDB · error

Could not find a SpacetimeDB module in spacetimedb/ or the c

Error message

Could not find a SpacetimeDB module in spacetimedb/ or the current directory. Use --module-path to specify the module location.

What it means

`spacetime build` without --module-path calls find_module_path(cwd), which checks for a spacetimedb/ subdirectory and then the current directory, accepting one as the module only if it contains Cargo.toml (Rust) or a *.csproj (C#). Returning None means neither location looks like a module, so the build has no target and the CLI asks for an explicit --module-path.

Source

Thrown at crates/cli/src/subcommands/build.rs:52

                .help("Additional features to pass to the build process (e.g. `--features feature1,feature2` for Rust modules).")
                // We're hiding this because we think it deserves a refactor first (see the TODO above)
                .hide(true)
        )
        .arg(
            Arg::new("debug")
                .long("debug")
                .short('d')
                .action(SetTrue)
                .help("Builds the module using debug instead of release (intended to speed up local iteration, not recommended for CI)"),
        )
        .arg(common_args::dotnet_version())
}

pub async fn exec(_config: Config, args: &ArgMatches) -> Result<(PathBuf, &'static str), anyhow::Error> {
    let module_path = match args.get_one::<PathBuf>("module_path").cloned() {
        Some(path) => path,
        None => find_module_path(&std::env::current_dir()?).ok_or_else(|| {
            anyhow::anyhow!(
                "Could not find a SpacetimeDB module in spacetimedb/ or the current directory. \
                 Use --module-path to specify the module location."
            )
        })?,
    };
    let features = args.get_one::<OsString>("features");
    let lint_dir = args.get_one::<OsString>("lint_dir").unwrap();
    let lint_dir = if lint_dir.is_empty() {
        None
    } else {
        Some(PathBuf::from(lint_dir))
    };
    let build_debug = args.get_flag("debug");
    let features = features.cloned();
    let dotnet_version = args.get_one::<u8>("dotnet_version").copied();

    run_build(module_path, lint_dir, build_debug, features, false, dotnet_version)
}

View on GitHub (pinned to 524b4487d9)

Solutions

  1. cd into the module directory (the one containing Cargo.toml or the .csproj) and re-run `spacetime build`
  2. Or point at it explicitly: `spacetime build --module-path path/to/module`
  3. For a new project, run `spacetime init` first to scaffold the module layout

Example fix

# before (repo root, module nested under server/)
spacetime build

# after
spacetime build --module-path server/
Defensive patterns

Strategy: validation

Validate before calling

# Detect a module the same way the CLI does, before building
is_module_dir() { [ -f "$1/Cargo.toml" ] || ls "$1"/*.csproj >/dev/null 2>&1; }
if ! is_module_dir ./spacetimedb && ! is_module_dir .; then
  echo 'no module here; pass --module-path' >&2; exit 1
fi
spacetime build

Type guard

fn looks_like_module(p: &Path) -> bool {
    p.join("Cargo.toml").exists()
        || p.read_dir().map(|it| it.flatten().any(|e| e.path().extension() == Some("csproj".as_ref()))).unwrap_or(false)
}

Try / catch

match build::exec(config, args).await {
    Ok(v) => v,
    Err(e) if e.to_string().contains("Could not find a SpacetimeDB module") => {
        // resolve an explicit module path from the caller and retry
        return Err(e.context("pass --module-path or run from the module directory"));
    }
    Err(e) => return Err(e),
}

Prevention

When it happens

Trigger: Running `spacetime build` from a directory (or a dir without a spacetimedb/ child) that has no Cargo.toml and no .csproj — e.g. a repo root, a scripts folder, or before the module project was created.

Common situations: Building from the repository root instead of the module directory in a fresh clone; module lives at a nonstandard nested path; module folder renamed; new project where `spacetime init` was never run.

Related errors


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