Error with wasm-pack and wasm-bindgen: `Reference` does not implement `FromWasmABI`
Here is some code I wrote in a newly generated wasm-pack project:
#[wasm_bindgen]
pub fn play_game(canvas: Reference) {
// enable console.error panic messages for debugging
set_panic_hook();
let canvas: CanvasElement = canvas.try_into().unwrap_or_else(|err| {
panic!("passed a non-canvas element. {}", err);
});
let rendering_context: CanvasRenderingContext2d = canvas.get_context().unwrap_or_else(|err| {
panic!("could not get 2d rendering context from canvas element: {}", err);
});
rendering_context.stroke_text("Hello, World!", 0f64, 0f64, None);
}
It seems to work fine when I run cargo check or cargo build. However, when I run wasm-pack build, I get this error message:
error[E0277]: the trait bound `stdweb::webcore::value::Reference: wasm_bindgen::convert::traits::FromWasmAbi` is not satisfied
--> src/lib.rs:20:1
|
20 | #[wasm_bindgen]
| ^^^^^^^^^^^^^^^ the trait `wasm_bindgen::convert::traits::FromWasmAbi` is not implemented for `stdweb::webcore::value::Reference`
It may be a bug in wasm-pack, but I thought I'd start here since AFAIK it's a goal of this project to be compatible with wasm-bindgen and wasm-pack.
Here is the full source: https://github.com/mikeyhew/wasm-pack-stdweb-error. It will take some time to compile, but here are the minimal steps. My rustc version is rustc 1.36.0-nightly (e305df184 2019-04-24) but try with whatever version you have first.
cargo install wasm-pack
git clone https://github.com/mikeyhew/wasm-pack-stdweb-error
cd wasm-pack-stdweb-error
cargo build # just to confirm that it works without errors
wasm-pack build # this should produce the above error message
This is currently expected due to stdweb's limited operability with wasm-bindgen. I intend to fix this in the future.