tauri-apps/tauri · error
Could not read binary file.
Error message
Could not read binary file.
What it means
In tauri-bundler's patch_binary, after bundling the app the bundler re-reads the compiled application binary to overwrite the __TAURI_BUNDLE_TYPE_VAR__ token with the package type (deb/rpm/appimage/msi/nsis). This expect fires when std::fs::read on the binary path returns an Err — the file is missing, moved, locked, or unreadable at patch time.
Source
Thrown at crates/tauri-bundler/src/bundle.rs:88
crate::PackageType::MacOsBundle | crate::PackageType::Dmg => {
// skip patching for macOS-native bundles
return Ok(());
}
_ => {
return Err(crate::Error::InvalidPackageType(
package_type.short_name().to_owned(),
"macOS".to_owned(),
))
}
};
log::info!(
"Patching {} with bundle type information: {}",
display_path(binary),
package_type.short_name()
);
let mut file_data = std::fs::read(binary).expect("Could not read binary file.");
let bundle_var_index =
kmp::index_of(BUNDLE_VAR_TOKEN, &file_data).ok_or(crate::Error::MissingBundleTypeVar)?;
file_data[bundle_var_index..bundle_var_index + BUNDLE_VAR_TOKEN.len()]
.copy_from_slice(bundle_type);
std::fs::write(binary, &file_data).map_err(|e| crate::Error::BinaryWriteError(e.to_string()))?;
Ok(())
}
/// Generated bundle metadata.
#[derive(Debug)]
pub struct Bundle {
/// The package type.
pub package_type: PackageType,
/// All paths for this package.
pub bundle_paths: Vec<PathBuf>,
}View on GitHub (pinned to 52e4b6e71d)
Solutions
- Rebuild from scratch with tauri build (or cargo tauri build) so the binary exists immediately before patching
- Check the exact path in the preceding log line 'Patching <path> with bundle type information' and verify it exists and is readable
- Confirm the binary name matches productName/binary in tauri.conf.json and the --target triple passed to the CLI
- On Windows, exclude the target directory from antivirus/Defender real-time scanning
Example fix
# before — bundling against a target dir whose artifacts were removed cargo clean && tauri bundle # after — let tauri build produce the binary right before bundling tauri build --bundles deb
Defensive patterns
Strategy: validation
Validate before calling
// Rust — before invoking bundling programmatically
let binary = std::path::Path::new("target/release/my-app");
if !binary.is_file() {
anyhow::bail!("app binary missing at {} — run cargo build first", binary.display());
} Prevention
- Always enter bundling through tauri build / tauri bundle so cargo build precedes patch_binary
- Keep beforeBuildCommand/afterBuildCommand hooks from moving or deleting files under target/
- On Windows, add the target directory to antivirus exclusions
When it happens
Trigger: Running tauri build/bundle when the app binary path recorded for patching no longer exists (target dir cleaned or artifacts moved mid-run), when another process (antivirus, indexer) holds an exclusive lock on Windows, or when permissions deny read access to target/<profile>/<app>.
Common situations: Build hooks (beforeBuildCommand/afterBuildCommand) or scripts that move/delete artifacts between the cargo build and bundling phases; antivirus quarantining unsigned exes on Windows; binary name mismatch between tauri.conf.json (productName/binary) and the --target/features actually built; permission-restricted CI runners.
Related errors
- failed to read binary path
- asset protocol path "{path}" is not valid: {e}
- File does not exist at path: {path}
- Missing OS permission to access path "{path}": {e}
- Unexpected target triple {}
AI-assisted analysis of tauri-apps/tauri@52e4b6e71d (2026-08-20).
Data as JSON: /api/errors/5c90d9c1dac1077b.
Report an issue: GitHub.