{"record":{"id":"dd0e1bfcb07a202b","repo":"clockworklabs/SpacetimeDB","slug":"could-not-auto-detect-client-language-from-i","errorCode":null,"errorMessage":"Could not auto-detect client language from '{}'. If this is not correct, pass --lang or add a generate target in spacetime.json.","messagePattern":"Could not auto-detect client language from '(.+?)'\\. If this is not correct, pass --lang or add a generate target in spacetime\\.json\\.","errorType":"validation","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/subcommands/generate.rs","lineNumber":422,"sourceCode":"    Ok(runs)\n}\n\nfn detect_default_language(client_project_dir: &Path) -> anyhow::Result<Language> {\n    if client_project_dir.join(\"package.json\").exists() {\n        return Ok(Language::TypeScript);\n    }\n    if client_project_dir.join(\"Cargo.toml\").exists() {\n        return Ok(Language::Rust);\n    }\n    if let Ok(entries) = fs::read_dir(client_project_dir)\n        && entries\n            .flatten()\n            .any(|entry| entry.path().extension().is_some_and(|e| e == \"csproj\"))\n    {\n        return Ok(Language::Csharp);\n    }\n\n    anyhow::bail!(\n        \"Could not auto-detect client language from '{}'. \\\n         If this is not correct, pass --lang or add a generate target in spacetime.json.\",\n        client_project_dir.display()\n    );\n}\n\nfn language_cli_name(lang: Language) -> &'static str {\n    match lang {\n        Language::Rust => \"rust\",\n        Language::Csharp => \"csharp\",\n        Language::TypeScript => \"typescript\",\n        Language::UnrealCpp => \"unrealcpp\",\n    }\n}\n\npub fn default_out_dir_for_language(lang: Language) -> Option<PathBuf> {\n    match lang {\n        Language::Rust | Language::TypeScript => Some(PathBuf::from(\"src/module_bindings\")),","sourceCodeStart":404,"sourceCodeEnd":440,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/cli/src/subcommands/generate.rs#L404-L440","documentation":"When `--lang` is not given, generate guesses the client language from marker files in the client project directory (the config dir, or the current directory if none): `package.json` means TypeScript, `Cargo.toml` means Rust, and any `*.csproj` means C#. If the directory contains none of these markers, detection fails and generate asks you to be explicit. Note the order — a directory with both package.json and Cargo.toml is detected as TypeScript.","triggerScenarios":"`spacetime generate` with no `--lang` in an empty or freshly created client directory; a client written in a language with no bindings support (e.g. only .py/.go files); running outside the directory that holds the marker files.","commonSituations":"First run in a brand-new repo scaffolded by hand; client living in a subdirectory not covered by config-dir; marker files removed during a migration; monorepos where the root has no client markers.","solutions":["Pass `--lang rust` (or csharp / typescript / unrealcpp) explicitly","Add a generate target with a `lang` field to spacetime.json so detection is never needed","Run generate from the directory containing package.json / Cargo.toml / *.csproj"],"exampleFix":"# before — in a dir with no package.json/Cargo.toml/*.csproj\nspacetime generate\n\n# after\nspacetime generate --lang typescript","handlingStrategy":"validation","validationCode":"# Detect what generate will detect, before running it:\ndetect_client_language() {\n  [[ -f package.json ]] && { echo typescript; return; }\n  [[ -f Cargo.toml ]]   && { echo rust; return; }\n  ls *.csproj >/dev/null 2>&1 && { echo csharp; return; }\n  echo none\n}\nif [[ -z \"$LANG_ARG\" ]] && [[ $(detect_client_language) == none ]]; then\n  echo \"cannot auto-detect language — pass --lang\" >&2; exit 2\nfi\nspacetime generate","typeGuard":"// Rust: mirror the CLI's detection so callers can decide instead of failing.\nfn detect_client_language(dir: &Path) -> Option<&'static str> {\n    if dir.join(\"package.json\").exists() { return Some(\"typescript\"); }\n    if dir.join(\"Cargo.toml\").exists() { return Some(\"rust\"); }\n    if dir.read_dir().ok()?.flatten().any(|e| e.path().extension().is_some_and(|x| x == \"csproj\")) {\n        return Some(\"csharp\");\n    }\n    None\n}","tryCatchPattern":null,"preventionTips":["Always pass --lang (or set `lang` on each generate target) in scripted environments","Remember detection order: package.json wins over Cargo.toml in mixed directories","Run generate from the client project root so the marker files are visible"],"tags":["generate","language-detection","cli"],"backgroundTag":"client-language-detection-failed","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}