tauri-apps/tauri · error · anyhow::Error

Cannot define a sidecar with the same name as the Cargo pack

Error message

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.

What it means

tauri-build copies each sidecar (bundle.externalBin) into the bundle next to the main executable, stripping the target-triple suffix (e.g. -x86_64-unknown-linux-gnu) from the file name first. If the resulting name equals the Cargo package name, the copy would clobber the app's own binary, so the build aborts with this explicit collision error.

Source

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

}

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(())
}

/// Copies resources to a path.
fn copy_resources(resources: ResourcePaths<'_>, path: &Path) -> Result<()> {
  let path = path.canonicalize()?;
  let mut resources = resources.iter();

View on GitHub (pinned to 2f1cd75b0f)

Solutions

  1. Rename the sidecar binary on disk (e.g. myapp -> myapp-helper) keeping the target-triple suffix, and update the externalBin entry in tauri.conf.json to match
  2. Alternatively rename the Cargo package if the binary file name must stay as-is (usually the heavier change)
  3. Rebuild; the collision check runs on every tauri build

Example fix

// before: binaries/myapp-x86_64-unknown-linux-gnu + package name 'myapp'
"externalBin": ["binaries/myapp-x86_64-unknown-linux-gnu"]

// after: renamed file binaries/myapp-helper-x86_64-unknown-linux-gnu
"externalBin": ["binaries/myapp-helper-x86_64-unknown-linux-gnu"]
Defensive patterns

Strategy: validation

Validate before calling

// prebuild check: sidecar name (minus target triple) must differ from package name
const { readFileSync } = require('fs')
const pkg = JSON.parse(readFileSync('src-tauri/Cargo.toml', 'utf8')) // or parse toml properly
const cfg = JSON.parse(readFileSync('src-tauri/tauri.conf.json', 'utf8'))
const name = /name\s*=\s*"([^"]+)"/.exec(readFileSync('src-tauri/Cargo.toml', 'utf8'))[1]
for (const b of cfg.bundle?.externalBin ?? []) {
  const base = b.split('/').pop().replace(/-[a-z0-9_-]+-(musl|gnu|msvc)$/, '')
  if (base === name) throw new Error(`sidecar ${b} collides with package name ${name}`)
}

Prevention

When it happens

Trigger: bundle.externalBin contains an entry whose file name, after removing the '-<target_triple>' suffix, equals the crate's package name - e.g. package 'myapp' with external binary 'myapp-x86_64-unknown-linux-gnu' resolving to file_name 'myapp'.

Common situations: Trying to ship a helper binary named the same as the app; renaming the project so the crate name now collides with an existing sidecar; templates where the sidecar was casually named after the app.

Related errors


AI-assisted analysis of tauri-apps/tauri@2f1cd75b0f (2026-08-16). Data as JSON: /api/errors/59acdb88e445cb0d. Report an issue: GitHub.