clockworklabs/SpacetimeDB · error · anyhow::Error

Built successfully but couldn't find a .wasm under {}

Error message

Built successfully but couldn't find a .wasm under {}

What it means

After the CMake build reports success, `build_cpp` walks the `build/` directory looking for any `*.wasm`, keeping the most recently modified match. If the recursive scan finds none, it returns this error with the build dir path: the toolchain ran, but produced no WebAssembly artifact where the CLI expects it.

Source

Thrown at crates/cli/src/tasks/cpp.rs:104

    // picking up an older cached wasm file from a previous build
    let wasm = WalkDir::new(&build_dir)
        .into_iter()
        .filter_map(Result::ok)
        .filter_map(|e| {
            let p = e.path();
            if p.extension().and_then(|s| s.to_str()) == Some("wasm") {
                e.metadata()
                    .ok()
                    .and_then(|m| m.modified().ok())
                    .map(|mtime| (p.to_path_buf(), mtime))
            } else {
                None
            }
        })
        .max_by_key(|(_, mtime)| *mtime)
        .map(|(path, _)| path)
        .ok_or_else(|| {
            anyhow!(
                "Built successfully but couldn't find a .wasm under {}",
                build_dir.display()
            )
        })?;

    Ok(wasm)
}

View on GitHub (pinned to 524b4487d9)

Solutions

  1. Delete the `build/` directory and rebuild with the emsdk env fully active, forcing reconfiguration with the Emscripten toolchain
  2. Inspect the project's CMakeLists for custom output directories and either point the build at `build/` or adjust expectations
  3. Verify the build actually targets wasm: look for `.wasm`-producing targets and check CMake cache toolchain settings in `build/CMakeCache.txt`
  4. Run `find <project>/build -name '*.wasm'` manually to see whether an artifact lands elsewhere

Example fix

# before
spacetime build .                     # built, but no .wasm under build/
# after
rm -rf build && source ~/emsdk/emsdk_env.sh && spacetime build .
Defensive patterns

Strategy: validation

Validate before calling

# After a clean build, assert the artifact exists where the CLI expects it
find build -name '*.wasm' | grep -q . || echo 'no wasm produced — check toolchain config'

Prevention

When it happens

Trigger: emcmake/cmake falling back to the host toolchain (producing native ELF/DLL objects instead of wasm because the Emscripten toolchain file wasn't applied to a stale or pre-existing CMake cache); a CMakeLists whose wasm-producing target writes outside `build/`; build artifacts cleaned by an external step between build and scan.

Common situations: A `build/` directory configured before emsdk activation, so CMake reuses a native generator cache; projects that copy/post-process outputs to `dist/`; custom output paths via `set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ...)` pointing elsewhere.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@524b4487d9 (2026-08-16). Data as JSON: /api/errors/43becfc94de78b91. Report an issue: GitHub.