When using webpack 5, enabling asyncWebAssembly: true in the webpack config will cause errors when trying to load a module generated from wasm-bindgen:
ReferenceError: Cannot access '__wbindgen_string_new' before initialization
The Rust code in question:
#[wasm_bindgen]
pub fn foo(n: &web_sys::HtmlElement) {
web_sys::console::log_1(&n.tag_name().into());
}
Commenting out this code, or replacing it with a fn foo(n: i32) { // ... } allows the code to function. Using syncWebAssembly: true also works as it did in webpack 4.
asyncWebAssembly should work.Minimal example repo based on rust-webpack-template:
git clone https://github.com/Herschel/webpack-testcd webpack-testnpm installnpm run startThe code should run successfully.
The following error is thrown:
ReferenceError: Cannot access '__wbindgen_string_new' before initialization
rustc 1.49.0-nightly (ffa2e7ae8 2020-10-24)
wasm-bindgen = "0.2.68"
web-sys = "0.3.45"
[email protected]
wasm-pack 0.9.1
"webpack": "^5.4.0"
Thanks for the report! I'm not entirely sure what changed in Webpack 5, but it at least looks like we need to account for something! I'd need to dig into how things changed and also any recent updates on the ESM proposal, if any. I don't have a ton of time for this but I'll try to make some time in the near future.
Most helpful comment
Thanks for the report! I'm not entirely sure what changed in Webpack 5, but it at least looks like we need to account for something! I'd need to dig into how things changed and also any recent updates on the ESM proposal, if any. I don't have a ton of time for this but I'll try to make some time in the near future.