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, first verifies toolchain availability by searching PATH for `emcc` (`emcc.bat` on Windows). Emscripten's compiler driver is mandatory for wasm output, so its absence aborts before any configure/build step with this message pointing at `emsdk_env`.

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 524b4487d9)

Solutions

  1. Install/activate Emscripten: `source ~/emsdk/emsdk_env.sh` (run `./emsdk install latest && ./emsdk activate latest` first if needed)
  2. Verify with `emcc --version` in the exact shell you build from
  3. Restart the terminal/IDE after activating so PATH propagates
  4. On CI, add an emsdk setup step before `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

# Fail fast if Emscripten isn't active
command -v emcc >/dev/null || { echo 'emsdk not active'; exit 2; }
spacetime build .

Prevention

When it happens

Trigger: Running `spacetime build` on a C/C++ module (detected via CMakeLists.txt) in a shell where the Emscripten SDK has not been activated — no `emcc` on PATH.

Common situations: New machine without emsdk installed; a new terminal where `emsdk_env.sh` was never sourced; CI images lacking Emscripten; IDE-launched terminals that don't inherit the shell profile where emsdk was activated.

Related errors


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