Skip to content

WASM bundles fail when loaded via file:// URLs #7918

Closed

Description

@bspeice

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 ".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?

Activity

  1. xtuc commented on Aug 20, 2018

    @xtuc
    Contributor

    I think that's something that browser should change. arrayBuffer + instantiate too has many disadvantages.

    I'm not very familiar with Electron, could we load the wasm module using node and fs?

  2. xtuc commented on Aug 20, 2018

    @xtuc
    Contributor

    Btw here's a previous discussion: WebAssembly/design#1200

  3. bspeice commented on Aug 21, 2018

    @bspeice
    Author

    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.

  4. schmidtk commented on Aug 30, 2018

    @schmidtk

    Emscripten's boilerplate to load WebAssembly modules handles this situation with a graceful fallback to ArrayBuffer instantiation. A similar approach could be applied here in webpack.

    I tested this solution in the webpack output and it solved my problem in Electron. If anyone with more (any) webpack contribution experience would like to fix this via PR I would be forever grateful, otherwise I may be able to make time to take a crack at it.

  5. sokra commented on Sep 2, 2018

    @sokra
    Member

    Yep send a PR

  6. bspeice commented on Sep 3, 2018

    @bspeice
    Author

    I've started a PR, but it could use some assistance (I'm not sure what exactly is or would be failing in the integration tests). If anyone's able to help that would be great, otherwise feel free to use it as a starting point.

  7. xtuc commented on Sep 3, 2018

    @xtuc
    Contributor

    Thanks @bspeice for the PR.

    Maybe we can override window.fetch to throw an error only the first call, so the fallback will still work.

  8. webpack-bot commented on Mar 5, 2019

    @webpack-bot
    Contributor

    This issue had no activity for at least half a year.

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

  9. added
    status: staleNo author response after a needs: request; close candidate
    on Mar 5, 2019
  10. webpack-bot commented on Mar 20, 2019

    @webpack-bot
    Contributor

    Issue was closed because of inactivity.

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

  11. removed
    status: staleNo author response after a needs: request; close candidate
    on Mar 20, 2019
  12. bspeice commented on Mar 20, 2019

    @bspeice
    Author

    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.

  13. 12 remaining items

  14. removed
    status: staleNo author response after a needs: request; close candidate
    on Apr 9, 2020
  15. added
    status: staleNo author response after a needs: request; close candidate
    on Jul 9, 2020
  16. removed
    status: staleNo author response after a needs: request; close candidate
    on Jul 24, 2020
  17. alexander-akait commented on Jul 24, 2020

    @alexander-akait
    Member

    /cc @vankop fixed in webpack@5?

  18. vankop commented on Jul 24, 2020

    @vankop
    Contributor

    file://path/some.wasm should work.

    Feel free to report a bug if does not work.

  19. bspeice commented on Jul 24, 2020

    @bspeice
    Author

    Can confirm, everything does seem to be fixed in webpack 5.

  20. alexander-akait commented on Jul 24, 2020

    @alexander-akait
    Member

    @bspeice thanks!

  21. bspeice commented on Jul 24, 2020

    @bspeice
    Author

    One quick clarification after I did some further testing: while Webpack 5 does contain fixes needed to load WASM blobs asynchronously, it doesn't change the underlying issue (Content-Type unset for file:// URLs). I'm having issues trying to find when this was changed in Chrome (and thus Electron as well), but when using window.fetch('file://*.wasm'), the Content-Type now comes back as application/wasm.

  22. alexander-akait commented on Jul 25, 2020

    @alexander-akait
    Member

    @bspeice Can you open a new issue with reproducible steps?

  23. bspeice commented on Jul 25, 2020

    @bspeice
    Author

    @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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedMaintainers welcome a community PR for this

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions