webpack: Error in multithreading with wasm-pack and webassembly rust

Bug report

What is the current behavior?

When compiling https://github.com/iMplode-nZ/rust-webpack-multithreading-test via (p)npm watch using webpack 5.49.0 and the latest rust and the rust flags -Ctarget-feature=+atomics,+bulk-memory,+mutable-globals, I get this error:

webpack compiled with 1 error
ERROR in ./pkg/index_bg.wasm
Module parse failed: Unexpected section: 0xc
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
Error: Unexpected section: 0xc

If the current behavior is a bug, please provide the steps to reproduce.

Clone https://github.com/iMplode-nZ/rust-webpack-multithreading-test, npm install, npm serve.

What is the expected behavior?

It does not error.

Other relevant information: webpack version: 5.49.0 Node.js version: 14.4.0 Operating System: Ubuntu 20.04 focal Additional tools:

rustc 1.56.0-nightly (4e282795d 2021-07-31)
wasm-bindgen 0.2.75
wasm-pack 0.10.0

I’m putting this here as it seems more like a webpack bug than a wasm-pack/bindgen/rust bug. See wasm-pack issue at https://github.com/rustwasm/wasm-pack/issues/1050

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 15 (6 by maintainers)

Most upvoted comments

Same issue here

“Unexpected section: 0xc” throws in wasm-async, or more precisely it crashes in @webassemblyjs/wasm-parser. This is a minimal example to reproduce the error:

const { decode } = require("@webassemblyjs/wasm-parser");
const fs = require('fs');

decode(fs.readFileSync('file.wasm'), {
  ignoreCodeSection: true,
  ignoreDataSection: true,
  ignoreCustomNameSection: true,
})

example files to reproduce: wasm_parse_bug.zip

I compiled the hello world example with wasm-pack:

wasm_parse_bug/hello_wasm_bg_working.wasm: (this works perfectly fine in webpack) compiled with: wasm-pack build

wasm_parse_bug/hello_wasm_bg_broken.wasm: (this causes the 0xc error) compiled with: RUSTFLAGS="-C target-feature=+atomics,+bulk-memory,+mutable-globals" wasm-pack build

@wrightwriter Please avoid such comments, it will not allow to help you, provide infromation/reproducible example