{"record":{"id":"43becfc94de78b91","repo":"clockworklabs/SpacetimeDB","slug":"built-successfully-but-couldn-t-find-a-wasm-under","errorCode":null,"errorMessage":"Built successfully but couldn't find a .wasm under {}","messagePattern":"Built successfully but couldn't find a \\.wasm under (.+?)","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"crates/cli/src/tasks/cpp.rs","lineNumber":104,"sourceCode":"    // picking up an older cached wasm file from a previous build\n    let wasm = WalkDir::new(&build_dir)\n        .into_iter()\n        .filter_map(Result::ok)\n        .filter_map(|e| {\n            let p = e.path();\n            if p.extension().and_then(|s| s.to_str()) == Some(\"wasm\") {\n                e.metadata()\n                    .ok()\n                    .and_then(|m| m.modified().ok())\n                    .map(|mtime| (p.to_path_buf(), mtime))\n            } else {\n                None\n            }\n        })\n        .max_by_key(|(_, mtime)| *mtime)\n        .map(|(path, _)| path)\n        .ok_or_else(|| {\n            anyhow!(\n                \"Built successfully but couldn't find a .wasm under {}\",\n                build_dir.display()\n            )\n        })?;\n\n    Ok(wasm)\n}\n","sourceCodeStart":86,"sourceCodeEnd":112,"githubUrl":"https://github.com/clockworklabs/SpacetimeDB/blob/524b4487d949b61a07d4f39c862d1290259dfd20/crates/cli/src/tasks/cpp.rs#L86-L112","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Delete the `build/` directory and rebuild with the emsdk env fully active, forcing reconfiguration with the Emscripten toolchain","Inspect the project's CMakeLists for custom output directories and either point the build at `build/` or adjust expectations","Verify the build actually targets wasm: look for `.wasm`-producing targets and check CMake cache toolchain settings in `build/CMakeCache.txt`","Run `find <project>/build -name '*.wasm'` manually to see whether an artifact lands elsewhere"],"exampleFix":"# before\nspacetime build .                     # built, but no .wasm under build/\n# after\nrm -rf build && source ~/emsdk/emsdk_env.sh && spacetime build .","handlingStrategy":"validation","validationCode":"# After a clean build, assert the artifact exists where the CLI expects it\nfind build -name '*.wasm' | grep -q . || echo 'no wasm produced — check toolchain config'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Delete `build/` before building whenever the emsdk activation state changed, so CMake can't reuse a native-toolchain cache","Confirm CMakeLists emits its wasm target into the build directory (default CMAKE output paths)","Verify `CMAKE_C_COMPILER` in build/CMakeCache.txt points at emcc after configuring"],"tags":["spacetimedb","cpp","wasm","build-artifact","cmake"],"backgroundTag":"missing-build-artifact","analyzedSha":"524b4487d949b61a07d4f39c862d1290259dfd20","analyzedAt":"2026-08-16T23:58:54.611Z","schemaVersion":2},"datasetVersion":"2026-08-17T04:17:16.089Z"}