wasm-bindgen icon indicating copy to clipboard operation
wasm-bindgen copied to clipboard

Uncaught (in promise) LinkError: import object field '__wbg_error_09919627ac0992f5' is not a Function + JsValue(undefined) instead of objects

Open Niedzwiedzw opened this issue 3 years ago • 5 comments

that happens when I import a package generated by wasm-pack

Niedzwiedzw avatar Jan 28 '22 13:01 Niedzwiedzw

https://github.com/nshen/vite-plugin-wasm-pack this partially solved it

Niedzwiedzw avatar Jan 28 '22 15:01 Niedzwiedzw

now the problem is that despite me passing an object into a function, what goes into wasm is read as null. invalid type: null, expected struct ScheduleImportConfigV2 at line 1 column 4

Niedzwiedzw avatar Jan 28 '22 16:01 Niedzwiedzw

yeah so I've triple checked it with console.log(myInput) on javascript side just beforre passing that into a wasm function

console.log(myInput) // {a: 1, b: 2}
myWasmPackage.handle_my_input(myInput)

and in rust it's

#[wasm_bindgen(skip_typescript)]
pub fn handle_my_input(my_data: JsValue) -> JsResult<JsValue> {
    console_log!(
        "handle_my_input :: {:#?}",
        my_data
    );
    // ...

}

and it prints

handle_my_input :: JsValue(undefined)

Niedzwiedzw avatar Jan 28 '22 19:01 Niedzwiedzw

https://github.com/Niedzwiedzw/vite-wasm-pack-error-showcase here's a repository showcasing this problem

Niedzwiedzw avatar Jan 28 '22 21:01 Niedzwiedzw

I'm attempting to reproduce it but encountered an error building your Rust code:

image

Could you please test it using my plugin https://www.npmjs.com/package/vite-plugin-wasm and the bundler target?

Menci avatar Mar 05 '22 15:03 Menci