Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[Bug]: wasm js bindings generated by wasm-pack is not compatible with raw browser import #268

Open
1 task done
wighawag opened this issue Sep 7, 2024 · 5 comments
Open
1 task done
Assignees
Labels
bug Something isn't working

Comments

@wighawag
Copy link

wighawag commented Sep 7, 2024

Dojo.js Version

all

What happened?

Currently dojo.js use wasm-pack to generate the js boilerplate to load wasm in browser/node/etc...

Unfortunately wasm-pack generate js file that load wasm via es import (import * as wasm from "./<lib>.wasm") which is not support by browser.

Some bundler will magically transform such import so browser can import it, some other (like vite) requires a community plugin to make it work. But ideally dojoengine should work without such external tool and as such it would be great if dojo.js output a js boilerplate compatible with browser (without require any other toool)

It seems using the wasm-bindgen cli to generate the js binding generate the correct js so it can be loaded in browser without any extra bundler

What is the expected behavior?

I expect to be able to use dojo with raw browser import, without the need for a bundler

Steps to reproduce

generate import map for torii-client and its dependencies

set them up in the index.html and add a script that load the torii-client and you ll'see the following error:

Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "application/wasm". Strict MIME type checking is enforced for module scripts per HTML spec.

see reproduction repo : https://github.com/bug-reproduction/torii-wasm-in-browser

see codepen : https://codepen.io/wighawag/pen/RwzddBM

Trace

No response

Is there an existing issue for this?

  • I have searched the existing issues and verified no issue exits for this problem.
@wighawag wighawag added the bug Something isn't working label Sep 7, 2024
@ShantelPeters
Copy link

Hi @wighawag please can I take this up

@wighawag
Copy link
Author

@ShantelPeters I am not the maintainer of this repo

@ShantelPeters
Copy link

Alright thank you @wighawag

@wighawag
Copy link
Author

Linking the reply here : dojoengine/dojo.c#55 (comment)

It suggest to use --target no-modules but this is less than ideal. we should be able to use es module in modern browser. And I believe this require some more wiring on using it. though this might be always the case.

@ponderingdemocritus
Copy link
Contributor

yes, these wasm modules are annoying. I'll try and support this soon - or feel free to open PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
No open projects
Status: No status
Development

No branches or pull requests

4 participants