I'm trying to execute a component I compiled using wasmtime like so
pub fn main() -> Result<()> {
let mut config = Config::new();
config.wasm_component_model(true);
let engine = Engine::new(&config)?;
// let path = path::Path::new("/Users/interpretations/projects/witty/my-component.wasm");
let contents = fs::read("./my-component.wasm")
.expect("Something went wrong reading the file");
println!("PRINTING OUT SOME THIGNS");
println!("THE ACTUAL CONTENTS {:?}", contents);
let comp = Component::from_binary(&engine, &contents).unwrap();
// println!("Output: {}", wasmprinter::print_bytes(&comp).unwrap());
let linker = Linker::new(&engine);
let mut store = Store::new(&engine, ());
let instance = linker.instantiate(&mut store, &comp)?;
Ok(())
}
and I'm getting
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: failed to parse WebAssembly module
Caused by:
unknown binary version (at offset 0x4)', src/main.rs:17:57
Seems like maybe wasmparser isn't recognizing const KIND_COMPONENT: u16 = 0x01; when reading the binary?
Does this need to be enabled with a feature flag?
I've specified wasmtime = { version = "5.0.0", features = ["component-model"]} in my Cargo.toml
It's failing on the call to Component::from_binary
Is your .wasm file binary wasm? (or is it perhaps the text form?)
It's binary. I'm creating it by running
wasm-tools component new ./target/wasm32-wasi/debug/my-project.wasm \
-o my-component.wasm --adapt ./wasi_snapshot_preview1.wasm
This is just a guess as I'm not tracking changes closely, but the component model spec is under heavy development and its possible that your tools are out of sync with each other; are you using recent versions of both wasm-tools and wasmtime?
Fairly sure I'm using latest for both, 1.0.23 and 5.0.0. Can try and tinker with some version changes though
You might want to try the main branch of wasmtime.
Wasm-tools may have had a release with breaking changes after Wasmtime 5.0.0 got released.
It did, unfortunately. Latest published wasm-tools only works with main of wasmtime. wit-bindgen hasn't been updated yet either.
If you do want to use 5.0.0 of wasmtime, you may need to rollback wasm-tools a version or two (another format change happened nine days ago too). We're getting close to some stability in the component binary format, but not quite there yet.
Oh I take that back, it looks like wit-bindgen updated its deps yesterday (Alex was supposed to have the day off :eyes:)
Thanks for the updates!
Last updated: Dec 06 2025 at 06:05 UTC