Dev-dependencies make [Wasm module has an invalid import section] happen

Problem:
I am using Rust for container development, and dev-dependencies in Cargo.toml are only used for unit testing, but when the package references in dev-dependencies come in, it will cause an error in dfx deploy: Failed to install wasm.
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_p laceholder’ that is not exported by the runtime.”

If you remove the package reference in this dev-dependencies, you can execute dfx deploy normally

Expect:
dfx deploy can be executed normally

Environment:
macOS 13.3.1 (a)
dfx 0.13.1
rust 1.68.2
cdk 0.7.4
candid 0.8

1 Like

Which dependencies are they? Sometimes you can turn off the feature that includes wasm-bindgen

Here I think that dev-dependencies should not affect the final compiled wasm, rather than enabling or disabling the features of a lib of dev-dependencies.
I understand what you want to express is that the problem can be solved by disabling the features that do not support wasm. Yes, I can do this, but I think maybe dfx can solve this problem and make the lib used by unit tests more free:)

Thank you very much for your kind reply @lastmjs . I have indeed solved the problem in this way. I initiated this topic because I expect dfx to do better.

2 Likes