clockworklabs/SpacetimeDB · error · anyhow::Error

Could not detect the language of the module. Are you in a…

Error message

Could not detect the language of the module. Are you in a SpacetimeDB project directory?

What it means

Module language detection is marker-file based: Cargo.toml means Rust, any *.csproj directly inside the directory means C#, package.json means JavaScript, CMakeLists.txt means C++. When the directory exists but contains none of these markers, the CLI cannot decide how to build the module and bails with this message.

Solutions

  1. cd into the actual module directory or pass --module-path to it
  2. Create/restore the marker file: `cargo init` for Rust, restore the .csproj, package.json, or CMakeLists.txt
  3. If no project exists yet, scaffold one with `spacetime init`
  4. For C#, ensure the .csproj is directly inside the module dir, not in a child folder

Example fix

# before: cwd contains no marker file
$ spacetime build
error: Could not detect the language of the module.

# after: build from the directory containing Cargo.toml
$ cd module && spacetime build
Defensive patterns

Strategy: validation

Validate before calling

#!/usr/bin/env bash
[ -f Cargo.toml ] || [ -f package.json ] || [ -f CMakeLists.txt ] || compgen -G '*.csproj' >/dev/null \
  || { echo 'not a SpacetimeDB module dir (no marker file)' >&2; exit 1; }

Prevention

When it happens

Trigger: Running spacetime build/publish in an empty or unrelated directory; a module dir whose marker file is missing (Cargo.toml deleted, .csproj only in a subfolder, package.json not at the module root); pointing --module-path at the repo root instead of the module crate.

Common situations: Wrong cwd when invoking the CLI; freshly created directory never initialized; nested monorepo layout where the marker file sits one level deeper than the path given.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20). Data as JSON: /api/errors/22cf0e49ffa26f26. Report an issue: GitHub.

Appendix: source

Thrown at crates/cli/src/util.rs:284

        );
    }
    // check for Cargo.toml
    if path_to_module.join("Cargo.toml").exists() {
        Ok(ModuleLanguage::Rust)
    } else if path_to_module.is_dir()
        && path_to_module
            .read_dir()
            .map_err(|e| anyhow::anyhow!("Failed to read directory {}: {}", path_to_module.display(), e))?
            .flatten()
            .any(|entry| entry.path().extension() == Some("csproj".as_ref()))
    {
        Ok(ModuleLanguage::Csharp)
    } else if path_to_module.join("package.json").exists() {
        Ok(ModuleLanguage::Javascript)
    } else if path_to_module.join("CMakeLists.txt").exists() {
        Ok(ModuleLanguage::Cpp)
    } else {
        anyhow::bail!("Could not detect the language of the module. Are you in a SpacetimeDB project directory?")
    }
}

pub fn url_to_host_and_protocol(url: &str) -> anyhow::Result<(&str, &str)> {
    if contains_protocol(url) {
        let protocol = url.split("://").next().unwrap();
        let host = url.split("://").last().unwrap();

        if !VALID_PROTOCOLS.contains(&protocol) {
            Err(anyhow::anyhow!("Invalid protocol: {protocol}"))
        } else {
            Ok((host, protocol))
        }
    } else {
        Err(anyhow::anyhow!("Invalid url: {url}"))
    }
}

View on GitHub (pinned to 6dee26c6ef)