stdweb icon indicating copy to clipboard operation
stdweb copied to clipboard

Error with wasm-pack and wasm-bindgen: `Reference` does not implement `FromWasmABI`

Open mikeyhew opened this issue 5 years ago • 1 comments

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

mikeyhew avatar May 31 '19 01:05 mikeyhew

This is currently expected due to stdweb's limited operability with wasm-bindgen. I intend to fix this in the future.

koute avatar Jun 03 '19 20:06 koute