clockworklabs/SpacetimeDB · error · anyhow::Error

Module directory does not exist

Error message

Module directory does not exist: '{}'. Check your --module-path flag or the module-path setting in spacetime.json.

What it means

Before probing a module's language, detect_module_language verifies that the module path exists at all. The path comes from the --module-path flag or the module-path setting in spacetime.json. A nonexistent path fails fast with this message instead of producing a confusing language-detection error later.

Solutions

  1. Verify the path exists: `ls` the directory you passed
  2. Run the CLI from the project root, or pass an absolute --module-path
  3. Fix the module-path value in spacetime.json
  4. If the module was deleted or never created, scaffold it with `spacetime init`

Example fix

# before
$ spacetime build --module-path ./src
error: Module directory does not exist: './src'

# after: point at the actual module directory
$ spacetime build --module-path ./crates/module
Defensive patterns

Strategy: validation

Validate before calling

#!/usr/bin/env bash
[ -d "$MODULE_PATH" ] || { echo "module dir missing: $MODULE_PATH" >&2; exit 1; }

Prevention

When it happens

Trigger: spacetime build/publish with --module-path pointing at a missing, renamed, or mistyped directory; running the CLI from a different working directory so a relative path no longer resolves; spacetime.json's module-path holding a stale location from another machine.

Common situations: Project folder moved or renamed after spacetime.json was written; a cloned repo carrying an absolute module-path; CI checkout layout differing from local; simple typo in the flag.

Understand the failure class

Background: "File not found" and ENOENT errors: why libraries can't find a file that should exist — this error's family across 50 libraries.

Related errors


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

Appendix: source

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

/// 1. `{project_dir}/spacetimedb/` subdirectory
/// 2. `{project_dir}` itself
///
/// Returns the first path that contains a recognizable SpacetimeDB module, or `None`.
pub fn find_module_path(project_dir: &Path) -> Option<PathBuf> {
    let spacetimedb_subdir = project_dir.join("spacetimedb");
    if spacetimedb_subdir.is_dir() && detect_module_language(&spacetimedb_subdir).is_ok() {
        return Some(spacetimedb_subdir);
    }
    if project_dir.is_dir() && detect_module_language(project_dir).is_ok() {
        return Some(project_dir.to_path_buf());
    }
    None
}

pub fn detect_module_language(path_to_module: &Path) -> anyhow::Result<ModuleLanguage> {
    // TODO: Possible add a config file durlng spacetime init with the language
    if !path_to_module.exists() {
        anyhow::bail!(
            "Module directory does not exist: '{}'. \
             Check your --module-path flag or the module-path setting in spacetime.json.",
            path_to_module.display()
        );
    }
    // 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)

View on GitHub (pinned to 6dee26c6ef)