webpack: WASM bundles fail when loaded via `file://` URLs

Bug report

What is the current behavior? Electron apps fail to load WASM code because WASM bundles served via file URL’s aren’t allowed to be loaded via instantiateStreaming (specifically because MIME application/wasm must be set.

If the current behavior is a bug, please provide the steps to reproduce. No configuration is specifically necessary, but I’ve included a reproducing project at this git repo. To run:

yarn install
./build.sh
yarn start

Running will require a recent Rust nightly build, but I’m happy to add the bundle files if necessary to skip that step.

What is the expected behavior? Webpack would detect that file URLs are not eligible for inclusion via instantiateStreaming and prioritize filling the arrayBuffer and instantiateing that instead.

Please note that I can specifically reproduce the correct behavior by snipping out the else if(...) WebAssembly.instantiateStreaming branch. I’m not sure what the right way of fixing this is, but I’m happy to work on a PR if someone can point me in the right direction.

Other relevant information: webpack version: 4.16.5 Node.js version: 8.10 Operating System: Linux Additional tools: Rust nightly


Alright, some updates after I spent more time looking at this: the actual URL request goes to “<hash>.wasm”, so adding checks for “./” or “file://” don’t fix this specific issue (though may not be a bad idea in general). Is this something that should potentially have a config value added instead, where we can disable streaming load?

About this issue

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

Most upvoted comments

@evilebottnawi: no need for a new issue. My intention was to clarify that the underlying issue was Chrome-related, and thus not something webpack could fix. The combination of browser and webpack changes that have come since this issue was opened make it so that everything works correctly. No further work needed, thanks all for the assistance.

Apologies for not responding - I’m not a JS developer so would have no idea how to safely apply an override like that. If everyone’s committed to that path, I’d need some help.

I’m admittedly totally unfamiliar with fs in node - my expectation is that you could load just fine, but you’d still have issues with the instantiateStreaming support. Some people I’ve talked with recommended effectively spinning up a static file server in-process to load the resource bundles (with appropriate MIME types) but this strikes me as a bit strange - I don’t particularly want to host a server inside the electron app.