clockworklabs/SpacetimeDB · error
Template '{}' has no git-tracked files! Check that the direc
Error message
Template '{}' has no git-tracked files! Check that the directory exists and contains files tracked by git. What it means
Build-time panic in crates/cli/build.rs while generating the embedded template registry: the template directory exists as an entry in templates-list.json but `git ls-files` (or the Nix file listing) returned zero tracked files for it. The CLI embeds template files into the binary at compile time, so an empty result means nothing would be embedded for that template — the build refuses to produce a CLI with a silently-empty template.
Source
Thrown at crates/cli/build.rs:262
}
fn generate_templates_json(templates: &[TemplateInfo]) -> String {
let payload = TemplatesJson { templates };
serde_json::to_string_pretty(&payload).expect("Failed to serialize templates JSON")
}
fn serialize_option_string_as_empty<S>(value: &Option<String>, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
serializer.serialize_str(value.as_deref().unwrap_or(""))
}
fn generate_template_entry(code: &mut String, template_path: &Path, source: &str, manifest_dir: &Path) {
let (git_files, resolved_base) = get_git_tracked_files(template_path, manifest_dir);
if git_files.is_empty() {
panic!("Template '{}' has no git-tracked files! Check that the directory exists and contains files tracked by git.", source);
}
let repo_root = get_repo_root();
code.push_str(" {\n");
code.push_str(" let mut files = HashMap::new();\n");
for file_path in git_files {
// Example file_path: modules/chat-console-rs/src/lib.rs (relative to repo root)
// Example resolved_base: modules/chat-console-rs
// Example relative_path: src/lib.rs
let relative_path = match file_path.strip_prefix(&resolved_base) {
Ok(p) => p,
Err(_) => {
eprintln!(
"Warning: Could not strip prefix '{}' from '{}' for source '{}'",
resolved_base.display(),
file_path.display(),View on GitHub (pinned to 6dee26c6ef)
Solutions
- From the repo root, stage the template: `git add templates/<template-name>` and confirm `git ls-files templates/<template-name>` lists files.
- Verify the `directory`/source field in templates/templates-list.json matches the on-disk folder name exactly (typo = zero matches).
- If building without git intentionally (e.g. Docker), set `SPACETIMEDB_NIX_BUILD_GIT_COMMIT` to switch build.rs onto the list-all-files path, or copy the full .git directory into the build context.
- Re-run `cargo build -p spacetimedb-cli` (or `spacetime build` of the CLI crate).
Example fix
# before git status --short # shows ?? templates/my-template/ # after git add templates/my-template git commit -m "Add my-template" cargo build -p spacetimedb-cli
Defensive patterns
Strategy: validation
Validate before calling
# Run from the repo root before building the CLI: for d in $(jq -r '.templates[].directory' templates/templates-list.json); do count=$(git ls-files "templates/$d" | wc -l) [ "$count" -gt 0 ] || echo "template $d has 0 git-tracked files" done
Prevention
- `git add` new template directories in the same commit that adds the list entry.
- Never build the CLI from a source copy with .git stripped (or set SPACETIMEDB_NIX_BUILD_GIT_COMMIT to take the list-all path).
- Run the ls-files check in CI for every PR touching templates/.
When it happens
Trigger: Adding a new template directory and an entry in templates/templates-list.json without `git add`ing the files; building the CLI from an exported tarball/source copy where .git metadata is absent while the non-Nix path runs `git ls-files`; renaming a template dir in the list but not on disk.
Common situations: Contributors who create template files but forget to stage them; building inside a Docker context that strips .git; CI checking out with a partial clone that excludes the template paths.
Related errors
- Failed to read_dir from template directory {}: {err:#?}
- Got error during read_dir from template directory {}: {err:#
- Failed to canonicalize path {}: {}
- Path {} is outside repo root {}
- Failed to canonicalize repo_root path {}: {err:#?}
AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20).
Data as JSON: /api/errors/1576bdf2da2c2cf4.
Report an issue: GitHub.