clockworklabs/SpacetimeDB · error
spacetime.json not found in {}
Error message
spacetime.json not found in {} What it means
A time-of-check/time-of-use race in config discovery: find_config_dir walks up from the current directory and only returns a directory where spacetime.json exists, then load_json_value immediately re-stats the same path and returns None if it no longer exists. So this error means spacetime.json was deleted or renamed between those two checks, inside a single command. The window is tiny, which is why this error is rare.
Source
Thrown at crates/cli/src/spacetime_config.rs:1030
/// Loading order (each overlays the previous via top-level key replacement):
/// 1. `spacetime.json` (required)
/// 2. `spacetime.local.json` (if exists)
/// 3. `spacetime.<env>.json` (if env specified and file exists)
/// 4. `spacetime.<env>.local.json` (if env specified and file exists)
pub fn find_and_load_with_env(env: Option<&str>) -> anyhow::Result<Option<LoadedConfig>> {
find_and_load_with_env_from(env, std::env::current_dir()?)
}
/// Find and load config with environment layering starting from a specific directory.
pub fn find_and_load_with_env_from(env: Option<&str>, start_dir: PathBuf) -> anyhow::Result<Option<LoadedConfig>> {
let config_dir = match find_config_dir(start_dir) {
Some(dir) => dir,
None => return Ok(None),
};
let base_path = config_dir.join("spacetime.json");
let mut merged = load_json_value(&base_path)?
.ok_or_else(|| anyhow::anyhow!("spacetime.json not found in {}", config_dir.display()))?;
mark_source_config(&mut merged, "spacetime.json");
let mut loaded_files = vec![base_path];
let mut has_dev_file = false;
// Overlay local file
let local_path = config_dir.join("spacetime.local.json");
if let Some(local_value) = load_json_value(&local_path)? {
overlay_json(&mut merged, local_value, "spacetime.local.json");
loaded_files.push(local_path);
}
// Overlay environment-specific file
if let Some(env_name) = env {
let env_path = config_dir.join(format!("spacetime.{env_name}.json"));
if let Some(env_value) = load_json_value(&env_path)? {
overlay_json(&mut merged, env_value, &format!("spacetime.{env_name}.json"));
loaded_files.push(env_path);View on GitHub (pinned to 524b4487d9)
Solutions
- Re-run the command — the race window is microseconds and a retry after the file settles almost always succeeds
- Serialize concurrent invocations: don't run `spacetime init`/config-rewriting steps in parallel with other spacetime commands in the same project
- If it persists, confirm the file actually exists in the reported directory (`ls <dir>/spacetime.json`) and that no daemon is deleting it
Example fix
# before: racing jobs make init & make publish & # init rewrites spacetime.json while publish discovers it # after: serialized make init && make publish
Defensive patterns
Strategy: retry
Validate before calling
# Pre-flight: assert the config file is present and stable before invoking the CLI
[ -f spacetime.json ] || { echo 'spacetime.json missing' >&2; exit 1; }
# guard against a formatter/init step rewriting it concurrently: wait until mtime settles
while [ "$(find spacetime.json -newermt '-2 seconds')" ]; do sleep 0.2; done Try / catch
for attempt in 1 2 3; do if spacetime "$@"; then exit 0; fi # this error is a discovery/load race; brief backoff then retry sleep 0.5 done exit 1
Prevention
- Never run config-rewriting commands (`spacetime init`, formatters) concurrently with other spacetime commands in one project
- In CI, create/repair spacetime.json in an earlier, serialized step before any command that reads it
When it happens
Trigger: Something removes or atomically replaces spacetime.json concurrently with a spacetime CLI invocation: another spacetime process (e.g. `spacetime init`) rewriting the config, an editor's atomic save (write temp + rename), a file watcher/formatter, or scripted cleanup.
Common situations: Two CLI commands racing in a Makefile/CI job (one deletes or re-inits the project while another runs); editors like VS Code or formatters doing rename-on-write saves at the moment of invocation.
Related errors
- Cannot use module-specific arguments ({}) when {}. {}
- Failed to parse config file {}: {}
- Database '{}' is not in the config file. If you want to run
- Unsupported --dotnet-version {version}. Supported values: 8,
- No such saved server configuration: {server} Add a new serve
AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16).
Data as JSON: /api/errors/31025dc9c03e6661.
Report an issue: GitHub.