15

I serve a static file server (through HTTP), which contains data generated by wasm-pack. Using the examples from the rustwasm book, I added this code to my index HTML page:

 <script type="module"> import init from "./pkg/fstree_web.js"; async function run() { await init(); } run(); </script> 

However, on Firefox, I get the error message as indicated in the title:

module from “http://localhost:8000/pkg/fstree_web_bg.wasm” was blocked because of a disallowed MIME type (“application/wasm”).

I suspected HTTPS issues or localhost issues, so I additionally tried 127.0.0.1, and even tried an https://***.ngrok.io tunnel, and Firefox still rejects loading the wasm module with this error message.

It links to an MDN article about X-Content-Type-Options, but I am not sure how it is relevant. My server is already sending Content-Type: application/wasm.

The JavaScript code generated by wasm-pack starts with this:

import { __cargo_web_snippet_72fc447820458c720c68d0d8e078ede631edd723 } from './snippets/stdweb-bb142200b065bd55/inline133.js'; import { __cargo_web_snippet_97495987af1720d8a9a923fa4683a7b683e3acd6 } from './snippets/stdweb-bb142200b065bd55/inline134.js'; import { __cargo_web_snippet_dc2fd915bd92f9e9c6a3bd15174f1414eee3dbaf } from './snippets/stdweb-bb142200b065bd55/inline135.js'; import { __cargo_web_snippet_1c30acb32a1994a07c75e804ae9855b43f191d63 } from './snippets/stdweb-bb142200b065bd55/inline136.js'; import { wasm_bindgen_initialize } from './snippets/stdweb-bb142200b065bd55/inline293.js'; import * as wasm from './fstree_web_bg.wasm'; 

Does Firefox want me to send *.wasm as a application/javascript? Or what is wrong?

3
  • Hey, if you post the previous link in a comment, I can tell you if there was an answer there or not. Commented Oct 13, 2019 at 13:57
  • stackoverflow.com/questions/58311656/… Commented Oct 13, 2019 at 13:58
  • Yeah, no one answered it. It was posted Oct 9 and deleted yesterday without a comment or answer. Commented Oct 13, 2019 at 14:00

2 Answers 2

14

The importing of WebAssembly modules is not yet standardized. You should set the --target argument of wasm-pack to web to generate JavaScript to use in a browser.

Sign up to request clarification or add additional context in comments.

7 Comments

I already did, but it generated the JavaScript above. The libraries I'm using, like stdweb, use snippets. Could that be related?
Is this an extension by any chance or a normal web page?
Doubt. I reproduce the same issue on chrome without any extensions
I was asking if you are developing an extension, but then I assume you are not.
Try to replace the wasm import line with direct instantiation of the module (developer.mozilla.org/en-US/docs/WebAssembly/…).
|
1

I am not sure if you have/had the same problem as me (trying to do the tutorial without using js-bundler), but I finally got it to work on my end.

Trying to attempt to get a handle on the *.wasm file you generated is already taken care of by the --target web parameter, so you don't actually need to import your *_bg.wasm file, but since the wasm Object (I'm not too sure yet, what this is) is actually returned by the init() function.

So if you want to carry on using the wasm handle, just do:

// Near imports worked for me, but choose your own scope let wasm; . . . // instead of await init(); wasm = await init(); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.