rustwasm / console_error_panic_hook

A panic hook for wasm32-unknown-unknown that logs panics with console.error
Apache License 2.0
319 stars 24 forks source link

Uncaught (in promise) TypeError: WebAssembly.instantiate(): Import #7 module="__wbindgen_placeholder__" error: module is not an object or function #14

Open Boscop opened 4 years ago

Boscop commented 4 years ago

When I try to use console_error_panic_hook in my yew project, my app panics on std::panic::set_hook(box console_error_panic_hook::hook) with:

Uncaught (in promise) TypeError: WebAssembly.instantiate(): Import #7 module="__wbindgen_placeholder__" error: module is not an object or function

I have the following [dependencies]:

yew = "0.11"
wasm-bindgen = "0.2"
console_error_panic_hook = "0.1.6"
#[wasm_bindgen(start)]
pub fn main_js() {
    #[cfg(debug_assertions)]
    std::panic::set_hook(box console_error_panic_hook::hook);
    web_logger::init();
    yew::initialize();
    App::<Model>::new().mount_to_body();
    yew::run_loop();
}

fn main() {
    main_js();
}
drewcrawford commented 4 years ago

Although I did not use this crate, I was able to resolve this issue by implementing a similar panic hook in stdweb:

#[macro_use]
extern crate stdweb;

fn main() {
    panic::set_hook(Box::new(|p| {
        let s = p.to_string();
        js!{ console.error(@{s});}
    }));
}
watzon commented 3 years ago

I get this same error when attempting to use wasm_bindgen::throw_str.