Wasm-bindgen: Incompatibility when using web_sys along with asyncWebAssembly in webpack 5

Created on 4 Nov 2020  路  1Comment  路  Source: rustwasm/wasm-bindgen

Describe the Bug

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.

2110 seems to indicate that asyncWebAssembly should work.

Steps to Reproduce

Minimal example repo based on rust-webpack-template:

  1. git clone https://github.com/Herschel/webpack-test
  2. cd webpack-test
  3. npm install
  4. npm run start
  5. Navigate to the page in the browser and view the JS console.

Expected Behavior

The code should run successfully.

Actual Behavior

The following error is thrown:

ReferenceError: Cannot access '__wbindgen_string_new' before initialization

Additional Context

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"
bug

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.

>All comments

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.

Was this page helpful?
0 / 5 - 0 ratings