wasm-pack icon indicating copy to clipboard operation
wasm-pack copied to clipboard

wasm-pack and webpack 5

Open BenoitDel opened this issue 4 years ago • 6 comments

I am trying to make wasm-pack and webpack 5 works together. They work well all together (out of the box) only for the most simple use case. If memory or imports are necessary, modification has to be made to the wasm-pack build to adjust with:

  • the new import syntax of webpack 5
  • the absence of node module like utils

I have several questions:

  • What is the roadmap for wasm-pack and webpack 5 ?
  • may i fill issue(s) about these compatibility problems ?
  • If yes, should i fill the issue here or on wasm-bindgen repo ?

BenoitDel avatar Apr 27 '20 13:04 BenoitDel

wasm-bindgen is taking care of it. wasm bindgen-2110

BenoitDel avatar Apr 29 '20 10:04 BenoitDel

A short update on Webpack 5 support. If you're using the most recent version of Webpack you need to add the following to webpack.config.js:

{
  module: {
    rules: [
      {
        test: /\.wasm$/,
        type: 'webassembly/sync',
      }
    ]
  },
  experiments: {
    syncWebAssembly: true
  }
}

Note that this requires the now deprecated syncWebAssembly backend. If you're getting the following error:

Uncaught (in promise) LinkError: WebAssembly.instantiate(): Import #0 module="./edmund_bg.js" function="__wbg_new_59cb74e423758ede" error: function import requires a callable

You're using the new experimental asyncWebAssembly backend that is currently not working too well with wasm-pack.

Given that the working configuration is now deprecated, I'm curious to how asyncWebAssembly will evolve and how it will integrate with wasm-pack. No idea if the error is a bug in Webpack or in this project.

samvv avatar Feb 03 '21 15:02 samvv

I'm currently diving into Web Assembly, and I was wondering what is this "new Web Assembly spec", and whether it's something that wasm-pack will handle, or is there a consideration that we need to take into working with Rust itself.

superjose avatar May 09 '21 13:05 superjose

Finally, I found this! CRA not work freaks me out, recommend add this content to README

tcper avatar Jul 16 '22 13:07 tcper

Any update on this? Still facing issues

HarikrishnanBalagopal avatar Mar 06 '23 18:03 HarikrishnanBalagopal

I am using webpack v5.88.2 and webpack-dev-server v4.15.1. I tried samvv's suggested changes in webpack.config.js, and still got the following error when trying to run webpack-dev-server:

export 'memory' (imported as 'memory') was not found in 'wasm-for-my-site/my_website_bg'

The export of the memory variable is supposed to be done by my_website_bg.wasm.d.ts, and this export works perfectly in webpack4, but not in webpack5.

webpack's frequent breaking of backwards compatibility is disappointing, to say the least. Its documentation also contains many grammar mistakes that some of the maintainers refuse to correct, even when given pull requests with corrections of those errors and no other changes.

I hope the Rust and WASM communities move on to better-documented and more consistent bundlers in the future.

klu235 avatar Sep 10 '23 01:09 klu235