{"record":{"id":"a235e0c4fd5acbf0","repo":"clockworklabs/SpacetimeDB","slug":"could-not-find-a-spacetimedb-module-in-spacetimedb","errorCode":null,"errorMessage":"Could not find a SpacetimeDB module in spacetimedb/ or the current directory. Use --module-path to specify the module location.","messagePattern":"Could not find a SpacetimeDB module in spacetimedb/ or the current directory\\. Use --module-path to specify the module location\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/build.rs","lineNumber":52,"sourceCode":"                .help(\"Additional features to pass to the build process (e.g. `--features feature1,feature2` for Rust modules).\")\n                // We're hiding this because we think it deserves a refactor first (see the TODO above)\n                .hide(true)\n        )\n        .arg(\n            Arg::new(\"debug\")\n                .long(\"debug\")\n                .short('d')\n                .action(SetTrue)\n                .help(\"Builds the module using debug instead of release (intended to speed up local iteration, not recommended for CI)\"),\n        )\n        .arg(common_args::dotnet_version())\n}\n\npub async fn exec(_config: Config, args: &ArgMatches) -> Result<(PathBuf, &'static str), anyhow::Error> {\n    let module_path = match args.get_one::<PathBuf>(\"module_path\").cloned() {\n        Some(path) => path,\n        None => find_module_path(&std::env::current_dir()?).ok_or_else(|| {\n            anyhow::anyhow!(\n                \"Could not find a SpacetimeDB module in spacetimedb/ or the current directory. \\\n                 Use --module-path to specify the module location.\"\n            )\n        })?,\n    };\n    let features = args.get_one::<OsString>(\"features\");\n    let lint_dir = args.get_one::<OsString>(\"lint_dir\").unwrap();\n    let lint_dir = if lint_dir.is_empty() {\n        None\n    } else {\n        Some(PathBuf::from(lint_dir))\n    };\n    let build_debug = args.get_flag(\"debug\");\n    let features = features.cloned();\n    let dotnet_version = args.get_one::<u8>(\"dotnet_version\").copied();\n\n    run_build(module_path, lint_dir, build_debug, features, false, dotnet_version)\n}","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/cli/src/subcommands/build.rs#L34-L70","documentation":"`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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["cd into the module directory (the one containing Cargo.toml or the .csproj) and re-run `spacetime build`","Or point at it explicitly: `spacetime build --module-path path/to/module`","For a new project, run `spacetime init` first to scaffold the module layout"],"exampleFix":"# before (repo root, module nested under server/)\nspacetime build\n\n# after\nspacetime build --module-path server/","handlingStrategy":"validation","validationCode":"# Detect a module the same way the CLI does, before building\nis_module_dir() { [ -f \"$1/Cargo.toml\" ] || ls \"$1\"/*.csproj >/dev/null 2>&1; }\nif ! is_module_dir ./spacetimedb && ! is_module_dir .; then\n  echo 'no module here; pass --module-path' >&2; exit 1\nfi\nspacetime build","typeGuard":"fn looks_like_module(p: &Path) -> bool {\n    p.join(\"Cargo.toml\").exists()\n        || p.read_dir().map(|it| it.flatten().any(|e| e.path().extension() == Some(\"csproj\".as_ref()))).unwrap_or(false)\n}","tryCatchPattern":"match build::exec(config, args).await {\n    Ok(v) => v,\n    Err(e) if e.to_string().contains(\"Could not find a SpacetimeDB module\") => {\n        // resolve an explicit module path from the caller and retry\n        return Err(e.context(\"pass --module-path or run from the module directory\"));\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Keep a spacetimedb/ subdirectory (or run builds from the directory holding Cargo.toml/.csproj)","In CI, set --module-path explicitly instead of relying on the working directory"],"tags":["spacetimedb","cli","build","module","path"],"backgroundTag":"module-not-found","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}