Hi. I'm getting this error with trying to use wit-bindgen on both host and guest:
Error: component imports instance
wasi:cli/environment@0.2.0, but a matching implementation was not found in the linkerCaused by: 0: instance export
get-environmenthas the wrong type 1: function > implementation is missing
I've created a test setup that includes all the source and how to build/run:
https://github.com/eirikb/wit-test
The *.wit file you're using isn't a perfect reflection of what the wasm binary is using, notably it omits all of WASI which the Rust standard library uses for its own implementation (e.g. getting env vars). This basically means that WASI is missing from your linker for which I'd recommend reading the wasmtime-wasi docs where you're likely interested in this function
Just noticed I was pointed to that link in another thread. Didn't notice. Sorry about that. Will take a look now!
I'm not sure if I need WASI. Perhaps I do in order for WIT to work? I don't plan on exposing anything from host to guest beside the methods I provide
For that you'd want to use wasm32-unknown-unknown as a compile target
to force the standard library to do nothing and have everything implemented as nops
I tried doing cargo build --target wasm32-unknown-unknown on the module, then point to that wasm file.
But then I get:
attempted to parse a wasm module with a component parser
If you're using cargo component you can continue using cargo component build, and if you're using cargo build you'll have to follow that up with wasm-tools component new to create a component
Ok tried cargo component build --target wasm32-unknown-unknown
And I think it ran. At least I didn't get any errors.
Since it doesn't do anything it is hard to tell. I will change the WIT to return a string
Oh my I think it worked! Nice
Thank you. I've updated the repo just in case someone stumbles over it
Last updated: Dec 06 2025 at 05:03 UTC