clockworklabs/SpacetimeDB · error · anyhow::Error

`emcc` not found in PATH. Activate Emscripten (emsdk_env).

Error message

`emcc` not found in PATH. Activate Emscripten (emsdk_env).

What it means

build_cpp, which compiles C/C++ modules to WebAssembly, preflights PATH for the Emscripten compiler driver (emcc / emcc.bat on Windows) and bails before configuring anything. Without emcc no WASM module can be produced, so the build stops immediately with a pointer to emsdk_env.

Solutions

  1. Activate Emscripten in this shell: `source <emsdk-path>/emsdk_env.sh` (Windows: `emsdk_env.bat`)
  2. If not installed: `git clone https://github.com/emscripten-core/emsdk && cd emsdk && ./emsdk install latest && ./emsdk activate latest`
  3. Verify with `emcc --version`, then re-run `spacetime build`

Example fix

# before
spacetime build            # emcc not found in PATH

# after
source ~/emsdk/emsdk_env.sh
spacetime build
Defensive patterns

Strategy: validation

Validate before calling

# bash: preflight the C/C++ toolchain before building
for t in emcc cmake emcmake; do command -v "$t" >/dev/null || { echo "missing $t — source emsdk_env.sh" >&2; exit 1; }; done
spacetime build

Prevention

When it happens

Trigger: `spacetime build` (or publish) on a module whose directory contains CMakeLists.txt, in a shell where Emscripten's environment has not been activated or was never installed.

Common situations: Fresh machines; opening a new terminal after installing emsdk (activation is per-shell); CI images without emsdk; Windows sessions where emsdk_env.bat was not run.

Related errors


AI-assisted analysis of clockworklabs/SpacetimeDB@6dee26c6ef (2026-08-20). Data as JSON: /api/errors/c9ee2121eec6b359. Report an issue: GitHub.

Appendix: source

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

    #[cfg(not(windows))]
    {
        duct::cmd(prog, args.iter().map(|s| s.as_ref()))
            .dir(cwd)
            .run()
            .with_context(|| format!("failed running `{prog}`"))?;
    }
    Ok(())
}

pub(crate) fn build_cpp(project_path: &Path, build_debug: bool) -> anyhow::Result<PathBuf> {
    // Verify required tools are in PATH
    #[cfg(windows)]
    let emcc_found = find_executable("emcc.bat").is_some();
    #[cfg(not(windows))]
    let emcc_found = find_executable("emcc").is_some();

    if !emcc_found {
        return Err(anyhow!("`emcc` not found in PATH. Activate Emscripten (emsdk_env)."));
    }

    #[cfg(windows)]
    let cmake_found = find_executable("cmake.exe").is_some();
    #[cfg(not(windows))]
    let cmake_found = find_executable("cmake").is_some();

    if !cmake_found {
        return Err(anyhow!("`cmake` not found in PATH."));
    }

    #[cfg(windows)]
    let emcmake_found = find_executable("emcmake.bat").is_some();
    #[cfg(not(windows))]
    let emcmake_found = find_executable("emcmake").is_some();

    if !emcmake_found {
        return Err(anyhow!("`emcmake` not found in PATH. Is Emscripten env active?"));

View on GitHub (pinned to 6dee26c6ef)