clockworklabs/SpacetimeDB · error · anyhow::Error
Module directory does not exist: '{}'. Check your --module-p
Error message
Module directory does not exist: '{}'. Check your --module-path flag or the module-path setting in spacetime.json. What it means
Thrown by detect_module_language in the SpacetimeDB CLI when the module path resolved from --module-path, the module-path setting in spacetime.json, or the auto-detected project directory does not exist on disk. The CLI refuses to build or publish because it cannot inspect the directory to determine the module language (Rust, C#, JavaScript/TypeScript, or C++). It always indicates a wrong or stale path, not a broken project.
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 524b4487d9)
Solutions
- Verify the directory exists (`ls <module-path>`) and fix typos or case sensitivity.
- Pass an explicit absolute path: `spacetime build --module-path /abs/path/to/module`.
- Check the module-path field in spacetime.json and make it relative to the config file or correct for the current layout.
- Run the command from inside the SpacetimeDB project directory (the one containing Cargo.toml, package.json, or a .csproj).
- If the module was never created, scaffold it first with `spacetime init`.
Example fix
// spacetime.json (before) — machine-specific absolute path
{ "module-path": "/home/me/old-path/module" }
// after — portable relative path
{ "module-path": "./module" } Defensive patterns
Strategy: validation
Validate before calling
#!/usr/bin/env bash
MODULE_PATH="${1:-.}"
if [ ! -d "$MODULE_PATH" ]; then
echo "module path '$MODULE_PATH' does not exist — fix --module-path / spacetime.json" >&2
exit 1
fi
spacetime build --module-path "$(cd "$MODULE_PATH" && pwd)" Prevention
- Always pass an absolute --module-path in CI scripts.
- Keep module-path in spacetime.json relative to the config file, never absolute.
- Run `spacetime init` before build in freshly cloned repositories.
When it happens
Trigger: Running `spacetime build` or `spacetime publish` with --module-path pointing to a nonexistent directory; a spacetime.json whose module-path value is stale or machine-specific; running the CLI from a working directory where find_module_dir can find neither a valid ./spacetime submodule dir nor a valid project dir.
Common situations: Typos or wrong case in --module-path; running commands from the repo root instead of the module crate directory; spacetime.json committed with an absolute path from another machine; moving or renaming the project folder after `spacetime init`.
Related errors
- Fatal Error: path {} exists but is not a directory.
- Fatal Error: path {} does not exist.
- Could not find a SpacetimeDB module in spacetimedb/ or the c
- Cannot continue without a module path.
- Project initialization did not create spacetimedb directory
AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16).
Data as JSON: /api/errors/89754e51948b4e69.
Report an issue: GitHub.