webpack icon indicating copy to clipboard operation
webpack copied to clipboard

WebAssembly with Reference Types cannot be parsed

Open CryZe opened this issue 3 years ago • 22 comments

Reopened #13559

Bug report

WebAssembly modules with enabled Reference Types cannot be loaded. The webpack version I tested this with is 5.38.1

For a minimal reproduction I created this repository: https://github.com/Tarnadas/webpack-5-wasm-reftypes

The error message is the following:

ERROR in ./pkg/webpack_5_wasm_reftypes_bg.wasm
Module parse failed: Internal failure: parseVec could not cast the value
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: Internal failure: parseVec could not cast the value
    at new CompileError (/home/marior/projects/webpack-5-wasm-reftypes/node_modules/@webassemblyjs/helper-api-error/lib/index.js:40:109)
    at parseVec (/home/marior/projects/webpack-5-wasm-reftypes/node_modules/@webassemblyjs/wasm-parser/lib/decoder.js:328:15)
    at parseTypeSection (/home/marior/projects/webpack-5-wasm-reftypes/node_modules/@webassemblyjs/wasm-parser/lib/decoder.js:360:22)
    at parseSection (/home/marior/projects/webpack-5-wasm-reftypes/node_modules/@webassemblyjs/wasm-parser/lib/decoder.js:1363:24)
    at Object.decode (/home/marior/projects/webpack-5-wasm-reftypes/node_modules/@webassemblyjs/wasm-parser/lib/decoder.js:1712:25)
    at decode (/home/marior/projects/webpack-5-wasm-reftypes/node_modules/@webassemblyjs/wasm-parser/lib/index.js:248:21)
    at WebAssemblyParser.parse (/home/marior/projects/webpack-5-wasm-reftypes/node_modules/webpack/lib/wasm-async/AsyncWebAssemblyParser.js:48:19)
    at /home/marior/projects/webpack-5-wasm-reftypes/node_modules/webpack/lib/NormalModule.js:1018:26
    at processResult (/home/marior/projects/webpack-5-wasm-reftypes/node_modules/webpack/lib/NormalModule.js:745:11)
    at /home/marior/projects/webpack-5-wasm-reftypes/node_modules/webpack/lib/NormalModule.js:809:5
 @ ./pkg/webpack_5_wasm_reftypes.js 1:0-58 4:0-21
 @ ./src/index.js 1:0-16

webpack 5.38.1 compiled with 1 error in 572 ms
error Command failed with exit code 1.

I used Rust with wasm-bindgen, which provides a cli option to enable reference types. Instead of directly using wasm-bindgen, I’ve been using wasm-pack, but since it’s unmaintained, you will need my fork to pass the cli option down to wasm-bindgen. You can see my PR for wasm-pack here: rustwasm/wasm-pack#888

By looking at the error message, it seems to be a problem with the wasm parser library. I checked its repository and couldn’t find any mentions about reference types unfortunately, so I’m not sure how to proceed with this.

CryZe avatar Mar 20 '22 19:03 CryZe

I think parser does not support them.. (@webassemblyjs/wasm-parser) . Right now there is no workaround for this.

vankop avatar Mar 21 '22 08:03 vankop

Why webpack try to parse it? can we just use file-loader?

enomado avatar Mar 24 '22 14:03 enomado

Why webpack try to parse it?

There are some exports optimization.. so webpack parsing wasm.

can we just use file-loader?

yes, sure. also in webpack@5 there is asset type.

vankop avatar Mar 24 '22 15:03 vankop

@xtuc

sokra avatar Apr 07 '22 11:04 sokra

This issue had no activity for at least three months.

It's subject to automatic issue closing if there is no activity in the next 15 days.

webpack-bot avatar Jul 07 '22 13:07 webpack-bot

ping

CryZe avatar Jul 07 '22 13:07 CryZe

Issue was closed because of inactivity.

If you think this is still a valid issue, please file a new issue with additional information.

webpack-bot avatar Oct 22 '22 07:10 webpack-bot

Last time you at least gave a warning, and it's marked as completed?? This has to be the worst bot ever.

CryZe avatar Oct 22 '22 10:10 CryZe

Ok dude

CryZe avatar Feb 06 '23 00:02 CryZe

@xtuc Friendly ping

alexander-akait avatar Jun 02 '23 16:06 alexander-akait