tauri-apps/tauri · error · std::io::Error
expected RGBA image data, found
Error message
expected RGBA image data, found {} What it means
Image::into_img() converts a JsImage received from JS (path, raw bytes, or RGBA) into an internal RGBA Image. Without the image-ico/image-png features enabled, the only supported variant is already-decoded RGBA data; any other JsImage variant triggers this io::Error (InvalidInput) describing what was found instead.
Solutions
- Enable the required Cargo features on the tauri crate: features = ["image-png"] (or "image-ico")
- Alternatively, decode the image in JS/Rust yourself and pass raw RGBA data with width/height
- Ensure the feature is enabled on the app crate, not only an intermediate workspace crate
Example fix
// before (Cargo.toml)
tauri = "2"
// after
tauri = { version = "2", features = ["image-png"] } Defensive patterns
Strategy: validation
Validate before calling
// Before calling setIcon/setTrayIcon from JS, pass RGBA data or ensure features enabled
const isRgba = (img) => img instanceof ImageData;
if (!isRgba(icon) && !import.meta.env.TAURI_IMAGE_FEATURES) {
throw new Error('enable tauri features image-png/image-ico or pass ImageData');
} Type guard
function isRgbaImage(v) { return v instanceof ImageData || (v && Array.isArray(v.rgba) && typeof v.width === 'number' && typeof v.height === 'number'); } Try / catch
try {
await appWindow.setIcon(iconPath);
} catch (e) {
if (String(e).includes('expected RGBA image data')) {
console.error('Enable tauri cargo feature image-png or pass RGBA ImageData', e);
}
} Prevention
- Enable tauri features image-png/image-ico when using file paths or encoded bytes for icons
- Prefer passing ImageData (raw RGBA) from the frontend for maximum portability
- Add the feature flags to workspace Cargo.toml to avoid them being dropped in refactors
When it happens
Trigger: Calling an API that takes an image (e.g. set window icon, tray icon) from JS passing a file path or raw encoded bytes while the tauri crate was built without the `image-png`/`image-ico` features.
Common situations: Using default Cargo features that exclude image decoding; passing a PNG file path to setIcon from the frontend; disabling default features and forgetting to re-add image support.
Related errors
- Cargo manifest must have the `package.version` field
- Cargo project does not have a version
- default_runtime requires the item to have at least 1…
- Failed to generate key
- failed to read cwd
AI-assisted analysis of tauri-apps/tauri@460ec35447 (2026-09-18).
Data as JSON: /api/errors/0d5dd2df535b5e45.
Report an issue: GitHub.
Appendix: source
Thrown at crates/tauri/src/image/mod.rs:210
/// the webview resources table.
pub fn into_img(self, resources_table: &ResourceTable) -> crate::Result<Arc<Image<'_>>> {
match self {
Self::Resource(rid) => resources_table.get::<Image<'static>>(rid),
#[cfg(any(feature = "image-ico", feature = "image-png"))]
Self::Path(path) => Image::from_path(path).map(Arc::new),
#[cfg(any(feature = "image-ico", feature = "image-png"))]
Self::Bytes(bytes) => Image::from_bytes(&bytes).map(Arc::new),
Self::Rgba {
rgba,
width,
height,
} => Ok(Arc::new(Image::new_owned(rgba, width, height))),
#[cfg(not(any(feature = "image-ico", feature = "image-png")))]
_ => Err(
std::io::Error::new(
std::io::ErrorKind::InvalidInput,
format!(
"expected RGBA image data, found {}",
match self {
JsImage::Path(_) => "a file path",
JsImage::Bytes(_) => "raw bytes",
_ => unreachable!(),
}
),
)
.into(),
),
}
}
}
View on GitHub (pinned to 460ec35447)