tauri-apps/tauri · error

{} `{}` failed with exit code {}

Error message

{} `{}` failed with exit code {}

What it means

`run_hook` executes config-defined hook scripts (such as `beforeBuildCommand`) via `sh -c` / `cmd /S /C` in the frontend directory (or the hook's configured `cwd`) with Tauri-provided env vars. If the script exits non-zero, the hook name, script text, and exit code are reported and the operation aborts.

Source

Thrown at crates/tauri-cli/src/helpers/mod.rs:117

      .piped()
      .map_err(|error| crate::error::Error::CommandFailed {
        command: script.clone(),
        error,
      })?;
    #[cfg(not(target_os = "windows"))]
    let status = Command::new("sh")
      .arg("-c")
      .arg(&script)
      .current_dir(cwd)
      .envs(env)
      .piped()
      .map_err(|error| Error::CommandFailed {
        command: script.clone(),
        error,
      })?;

    if !status.success() {
      crate::error::bail!(
        "{} `{}` failed with exit code {}",
        name,
        script,
        status.code().unwrap_or_default()
      );
    }
  }

  Ok(())
}

#[cfg(target_os = "macos")]
pub fn strip_semver_prerelease_tag(version: &mut semver::Version) -> crate::Result<()> {
  use crate::error::Context;
  if !version.pre.is_empty() {
    if let Some((_prerelease_tag, number)) = version.pre.as_str().to_string().split_once('.') {
      version.pre = semver::Prerelease::EMPTY;
      version.build = semver::BuildMetadata::new(&format!(

View on GitHub (pinned to 52e4b6e71d)

Solutions

  1. Run the exact script from the error message manually in the frontend dir and fix the failure it reports
  2. Ensure the binaries the script calls (npx, pnpm, node) are on PATH for non-interactive shells
  3. Install frontend dependencies before building (`npm ci`) if the script depends on local node_modules

Example fix

// before (tauri.conf.json) - script fails with exit code 1
"beforeBuildCommand": "npm run build && npm run test"

// after - keep the build hook minimal; run tests separately in CI
"beforeBuildCommand": "npm run build"
Defensive patterns

Strategy: validation

Validate before calling

# validate the hook script executes cleanly in a clean sh before building
sh -c 'cd frontend && npm ci --silent && npm run build' || { echo 'hook script failed'; exit 1; }
tauri build

Prevention

When it happens

Trigger: `tauri build` (or other phases calling `run_hook`) with a `beforeBuildCommand`/hook script that fails: missing dependencies, failing test/lint step embedded in the build script, or a script typo. Empty scripts are skipped, so only a non-empty failing script triggers this.

Common situations: CI where node_modules are absent and the build script imports a linter; scripts referencing binaries not on PATH in the hook's environment (`sh -c` non-login shell); frontend builds failing on out-of-memory or type errors.

Related errors


AI-assisted analysis of tauri-apps/tauri@52e4b6e71d (2026-08-20). Data as JSON: /api/errors/8163e2570d1e1752. Report an issue: GitHub.