Skip to content

WebAssembly with Reference Types cannot be parsed #15566

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
CryZe opened this issue Mar 20, 2022 · 39 comments · Fixed by #18940
Closed

WebAssembly with Reference Types cannot be parsed #15566

CryZe opened this issue Mar 20, 2022 · 39 comments · Fixed by #18940
Labels

Comments

@CryZe
Copy link

CryZe commented Mar 20, 2022

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.

@vankop
Copy link
Member

vankop commented Mar 21, 2022

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

@vankop vankop added webpack-5 wasm wasm related issues labels Mar 21, 2022
@enomado
Copy link

enomado commented Mar 24, 2022

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

@vankop
Copy link
Member

vankop commented Mar 24, 2022

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.

@sokra
Copy link
Member

sokra commented Apr 7, 2022

@xtuc

@webpack-bot
Copy link
Contributor

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.

@CryZe
Copy link
Author

CryZe commented Jul 7, 2022

ping

@webpack-bot
Copy link
Contributor

Issue was closed because of inactivity.

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

@CryZe
Copy link
Author

CryZe commented Oct 22, 2022

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

@CryZe
Copy link
Author

CryZe commented Feb 6, 2023

Ok dude

@alexander-akait
Copy link
Member

@xtuc Friendly ping

@alexander-akait
Copy link
Member

The same - #18940

@xtuc
Copy link
Member

xtuc commented Nov 6, 2024

Thanks for checking @alexander-akait . I'm having a look.

@xtuc
Copy link
Member

xtuc commented Nov 6, 2024

I published 1.14.1. Could you please try again @alexander-akait ?

Sorry I had some issues with my publish setup.

@mateuszJS
Copy link

@xtuc Works for me!

    "@webassemblyjs/ast": "^1.14.1",
    "@webassemblyjs/wasm-edit": "^1.14.1",
    "@webassemblyjs/wasm-parser": "^1.14.1",

https://github.com/mateuszJS/rust-webpack-v5-template/tree/webpack-v5-migration
Thank you for great work 👍

@stephanemagnenat
Copy link

@xtuc works for me as well! Thank you very much!

@ivnsch
Copy link

ivnsch commented Dec 22, 2024

I'm still getting the error "Module parse failed: Internal failure: parseVec could not cast the value"

https://github.com/ivnsch/molsimnext

the only way to fix it is still the workaround

[profile.release]
strip = true

@alexander-akait
Copy link
Member

@ivnsch what version do you use?

amatveiakin added a commit to amatveiakin/bughouse-chess that referenced this issue Dec 31, 2024
@ivnsch
Copy link

ivnsch commented Jan 4, 2025

@ivnsch what version do you use?

Version of webpack? It's a newly created nextjs project (npx create-next-app@latest). The webpack version is hidden for some reason, nowhere to be seen in the lock file, npm explain webpack, npx webpack --version etc. It might be 5.96.1 (it's confirmed that it's using webpack, because the webpack section in next.config.ts is executed).

I also tried specifying these dependencies as per post above:

    "@webassemblyjs/ast": "^1.14.1",
    "@webassemblyjs/wasm-edit": "^1.14.1",
    "@webassemblyjs/wasm-parser": "^1.14.1",

khanghugo added a commit to khanghugo/gchimp that referenced this issue Jan 9, 2025
it seems like nextjs is not updating their webpack. So for the time being, doing this will fix the issue
webpack/webpack#15566
sisou added a commit to nimiq/wallet that referenced this issue Jan 13, 2025
Webpack was running into webpack/webpack#15566 with the latest @nimiq/core version, but an update fixed it.
@j2ghz
Copy link

j2ghz commented Feb 3, 2025

Apart from the @webassemblyjs/* dependencies also check your webpack version. I was on 5.96.1 (latest nextjs), whereas 5.97.0 seems to have the fix:

[WASM] Don't crash WebAssembly with Reference Types (sync and async)
[WASM] Fixed wasm loading for sync and async webassembly

My problem before applying the fix above:
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

from my pnpm lockfile:

packages:
  '@webassemblyjs/ast@1.14.1':
    resolution: {integrity: sha512-nuBEDgQfm1ccRp/8bCQrx1frohyufl4JlbMMZ4P1wpeOfDhF6FQkxZJ1b/e+PLwr6X1Nhw6OLme5usuBWYBvuQ==}

  '@webassemblyjs/wasm-edit@1.14.1':
    resolution: {integrity: sha512-RNJUIQH/J8iA/1NzlE4N7KtyZNHi3w7at7hDjvRNm5rcUXa00z1vRz3glZoULfJ5mpvYhLybmVcwcjGrC1pRrQ==}

  '@webassemblyjs/wasm-parser@1.14.1':
    resolution: {integrity: sha512-JLBl+KZ0R5qB7mCnud/yyX08jWFw5MsoalJ1pQ4EdFlgj9VdXKGuENGsiCIjegI1W7p91rUlcB/LB5yRJKNTcQ==}

snapshots:
  webpack@5.96.1:
    dependencies:
      '@types/eslint-scope': 3.7.7
      '@types/estree': 1.0.6
      '@webassemblyjs/ast': 1.14.1
      '@webassemblyjs/wasm-edit': 1.14.1
      '@webassemblyjs/wasm-parser': 1.14.1

MikkelPaulson added a commit to initiative-sh/initiative.sh that referenced this issue Apr 5, 2025
MikkelPaulson added a commit to initiative-sh/initiative.sh that referenced this issue Apr 6, 2025
MikkelPaulson added a commit to initiative-sh/initiative.sh that referenced this issue Apr 6, 2025
alexjg added a commit to automerge/automerge that referenced this issue May 7, 2025
Problem: when using rustc > 1.82 and webpack < 5.97.0 the wasm file
generated by wasm-bindgen can't be loaded by webpack. This is tracked by
an issue [1] in the wasm-bindgen repo and an issue [2] in the webpack
repo. This meant that the packaging tests were failing.

Solution: upgrade the packaging tests to use webpack 5.99.0. This does
mean that people using older versions of webpack will need to upgrade,
but it's a patch version upgrade so shouldn't be too disruptive.

[1]: rustwasm/wasm-bindgen#4211
[2]: webpack/webpack#15566
alexjg added a commit to automerge/automerge that referenced this issue May 7, 2025
Problem: when using rustc > 1.82 and webpack < 5.97.0 the wasm file
generated by wasm-bindgen can't be loaded by webpack. This is tracked by
an issue [1] in the wasm-bindgen repo and an issue [2] in the webpack
repo. This meant that the packaging tests were failing.

Solution: upgrade the packaging tests to use webpack 5.99.0. This does
mean that people using older versions of webpack will need to upgrade,
but it's a patch version upgrade so shouldn't be too disruptive.

[1]: rustwasm/wasm-bindgen#4211
[2]: webpack/webpack#15566
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.