I used these dependencies to implement the signature verification of sr25519. The compilation passed, but an error was reported during local deploy. How to solve it
error message:
The Replica returned an error: code 5, message: “Wasm module of canister rwlgt-iiaaa-aaaaa-aaaaa-cai is not valid: Wasm module has an invalid import section. Module imports function ‘__wbindgen_describe’ from ‘wbindgen_placeholder’ that is not exported by the runtime.”
Just ran into this, adding what I found if someone wants to dig deeper.
This errors out
getrandom = { version = "0.2.6", features = ["js"]}
rand = "0.8.5"
Error: The Replica returned an error: code 5, message: “Wasm module of canister rrkah-fqaaa-aaaaa-aaaaq-cai is not valid: Wasm module has an invalid import section. Module imports function ‘__wbindgen_describe’ from ‘wbindgen_placeholder’ that is not exported by the runtime.”
This works
getrandom = { version = "0.2.3", features = ["js"]}
rand = "0.7.3"
The Replica returned an error: code 5, message: “Wasm module of canister r7inp-6aaaa-aaaaa-aaabq-cai is not valid: Wasm module has an invalid import section. Module imports function ‘__wbindgen_describe’ from ‘wbindgen_placeholder’ that is not exported by the runtime.”
I am also trying to use the uuid crate in my canister. When I use it I am getting a different kind of error but still similar to this:
Failed during wasm installation call: The replica returned a replica error: reject code CanisterError,
reject message Wasm module of canister bkyz2-fmaaa-aaaaa-qaaaq-cai is not valid: Wasm module has
an invalid import section. Module imports function '__wbg_crypto_58f13aa23ffcb166' from
'__wbindgen_placeholder__' that is not exported by the runtime., error code None
It’s trying to use functions that are not available in wasm32 I suppose. Is it because of somethin gin the base crate or does it only happen if you turn on certain features?
The error I above is only happening when I use the Uuid package, So I guess I need to checkout those custom principals/uuids.
But even after removing the Uuid. I am getting this similar error:
Failed to install wasm module to canister 'backend'.
Failed during wasm installation call: The replica returned a replica error: reject code CanisterError,
reject message Wasm module of canister bkyz2-fmaaa-aaaaa-qaaaq-cai is not valid: Wasm module has
an invalid import section. Module imports function '__wbindgen_describe' from '__wbindgen_placeholder__' that is not exported by the runtime., error code None
#[macro_use]
extern crate serde;
use candid::{Decode, Encode};
use ic_cdk::api::time;
use ic_stable_structures::memory_manager::{MemoryId, MemoryManager, VirtualMemory};
use ic_stable_structures::storable::Bound;
use ic_stable_structures::{ DefaultMemoryImpl, StableBTreeMap, Storable};
use std::{borrow::Cow, cell::RefCell};
You need to make sure that none of your dependencies depend on wasm bindgen. For example, getrandom you have the js feature set, that dooms you from the start. Start by turning off that feature. Then in your Cargo.lock file you can search for wasm-bindgen or bindgen etc and try to find out which dependencies are assuming a wasm-bindgen environment. Hopefully you can turn features on or off to deal with that, in the worst case you’d need to fork the project and remove the wasm-bindgen code yourself.