tauri-apps/tauri · critical

failed to extract external binary filename

Error message

failed to extract external binary filename

What it means

In tauri-build's copy_binaries, each external binary path is expected to have a final file name component; `Path::file_name()` returned None, so the `.expect` panics with this message. The library assumes sidecar paths always point to an actual file, and needs the filename to strip the target-triple suffix. It is a build-time panic, not a recoverable Result.

Solutions

  1. Fix the external binary path in tauri.conf.json so it ends with an actual file name (e.g. `binaries/myapp`).
  2. Verify the referenced sidecar binary exists and the path is not truncated (empty variable, missing extension handling).
  3. If building paths in a build script, normalize with `path.canonicalize()` or `std::path::absolute` before passing to copy_binaries.
  4. Assert the path with `assert!(src.is_file())` in your build script before calling try_build to fail early with a clearer message.

Example fix

// before (tauri.conf.json)
"externalBin": ["binaries/"]
// after
"externalBin": ["binaries/my-sidecar"]
Defensive patterns

Strategy: validation

Validate before calling

let src = std::path::Path::new("binaries/my-sidecar");
assert!(src.is_file(), "sidecar path is not a file: {}", src.display());
assert!(src.file_name().is_some(), "sidecar path has no filename component");

Type guard

fn has_file_name(p: &std::path::Path) -> bool { p.file_name().is_some() }

Prevention

When it happens

Trigger: Passing an `externalBin` entry whose path has no file name component — e.g. a path ending in `/`, `..`, `.`, or the filesystem root — to tauri_build::try_build via Attributes::copy_binaries.

Common situations: A Tauri config `bundle.externalBin` entry like `binaries/myapp-` or a mis-resolved path from a build script; generated paths where a variable was empty so the path collapses to a directory-like value; paths built by joining with trailing separators.

Related errors


AI-assisted analysis of tauri-apps/tauri@460ec35447 (2026-09-18). Data as JSON: /api/errors/c090d8d9f4788e3a. Report an issue: GitHub.

Appendix: source

Thrown at crates/tauri-build/src/lib.rs:69

  }
  let dest_dir = to.parent().expect("No data in parent");
  fs::create_dir_all(dest_dir)?;
  fs::copy(from, to)?;
  Ok(())
}

fn copy_binaries(
  binaries: ResourcePaths,
  target_triple: &str,
  path: &Path,
  package_name: Option<&str>,
) -> Result<()> {
  for src in binaries {
    let src = src?;
    println!("cargo:rerun-if-changed={}", src.display());
    let file_name = src
      .file_name()
      .expect("failed to extract external binary filename")
      .to_string_lossy()
      .replace(&format!("-{target_triple}"), "");

    if package_name == Some(&file_name) {
      return Err(anyhow::anyhow!(
        "Cannot define a sidecar with the same name as the Cargo package name `{}`. Please change the sidecar name in the filesystem and the Tauri configuration.",
        file_name
      ));
    }

    let dest = path.join(file_name);
    if dest.exists() {
      fs::remove_file(&dest).unwrap();
    }
    copy_file(&src, &dest)?;
  }
  Ok(())
}

View on GitHub (pinned to 460ec35447)