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
- cd into the actual module directory or pass --module-path to it
- Create/restore the marker file: `cargo init` for Rust, restore the .csproj, package.json, or CMakeLists.txt
- If no project exists yet, scaffold one with `spacetime init`
- 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
- Always invoke the CLI from the module root or pass --module-path explicitly
- Keep the marker file (Cargo.toml/package.json/.csproj/CMakeLists.txt) at the module dir top level
- Scaffold new modules with spacetime init so the layout is correct from the start
- In monorepos, script a mapping from project name to module dir
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
- Cannot determine module type from file extension
- Module directory does not exist
- Server template not found
- Aborted.
- Aborted.
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)