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

TypeError: Incorrect response MIME type. Expected 'application/wasm' #5

Closed
tennisonchan opened this issue Nov 26, 2017 · 6 comments
Closed

Comments

@tennisonchan
Copy link

Since application/wasm isn't an official MIME type yet, WebAssembly/spec#573, in case you got the type error of an incorrect response MIME type, you can add the following line in file /etc/mime.types and then restart the server.

application/wasm    wasm

FYI:
https://bugs.python.org/issue31670
python/cpython#3861

@timmyjose
Copy link

timmyjose commented Nov 24, 2018

Just wanted to make a note here for macOS users. For me, I was running into the same issue, and the suggestions online (of, say, adding a new MIME type to /etc/mime) do not work for macOS since there is no such file).

The following snippet does not work on macOS:

<script>
    WebAssembly.instantiateStreaming(fetch('my-file.wasm'))
      .then(obj => {
         // do something, say, print to console
         console.log(obj.instance.exports.my_func());
      });
  </script>

whereas the following does work:

<script>
  fetch('my-file.wasm').then(response => 
  	response.arrayBuffer()
  ).then(bytes => 
    WebAssembly.instantiate(bytes)
  ).then(obj => {
      console.log(obj.instance.exports.my_func());
  });
  </script>

Posting it here in case other frustrated people come across this looking for a solution on macOS.

@richlum
Copy link

richlum commented Dec 19, 2018

similar issue using 'web server for chrome' on linux. Adapted timmyjose solution while trying to follow along https://developer.mozilla.org/en-US/docs/WebAssembly/Text_format_to_wasm

<script>
  var importObject = {
    imports: { imported_func: arg => console.log(arg) }
  };
  fetch('simple.wasm').
  then(response => response.arrayBuffer()).
  then(bytes => WebAssembly.instantiate(bytes, importObject)).
  then(obj => obj.instance.exports.exported_func());

@lukewagner
Copy link
Contributor

I think python2 -m SimpleHTTPServer and python3 -m http.server should work for local testing nowadays.

Note that instantiateStreaming(Response) provides much better performance than instantiate(ArrayBuffer) so ideally an app would only use instantiate(ArrayBuffer) as a fallback when instantiateStreaming failed. (E.g., I think Unity and Emscripten do this.)

@H-arshit
Copy link

H-arshit commented Feb 5, 2019

<script> fetch('my-file.wasm').then(response => response.arrayBuffer() ).then(bytes => WebAssembly.instantiate(bytes) ).then(obj => { console.log(obj.instance.exports.my_func()); }); </script>

where do we have make these changes?

@lucidBrot
Copy link

I think python2 -m SimpleHTTPServer and python3 -m http.server should work for local testing nowadays.

Note that instantiateStreaming(Response) provides much better performance than instantiate(ArrayBuffer) so ideally an app would only use instantiate(ArrayBuffer) as a fallback when instantiateStreaming failed. (E.g., I think Unity and Emscripten do this.)

That did not directly work for me, however this gist provides a python server that does work

@VertikaJain
Copy link

You need to install static-server rather than http-server. This is because the WebAssembly module needs to be served with a MIME type of application/wasm, and the MIME type is provided in the static-server package.
For confirmation, you can cross check in your package-lock.json after installing both these packages using npm and compare the respective "requires" fields. The static-server will be having "mime": "^version_name" .
Check out my github repository on AssemblyScript for more detailed implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants