James
James

Reputation: 680

Electron WebAssembly: TypeError: Incorrect response MIME type. Expected 'application/wasm'

WebAssembly.instantiateStreaming fails when using a local relative path. Is there any way to disable this check or does anyone have any advice on another approach of getting around the problem? I'm trying to remove having the dependency of a web backend of my electron project.

<script>
    WebAssembly.instantiateStreaming(fetch("relative/path/to/file.wasm", {
        credentials: "same-origin",
        headers: {
            "Content-Type": "application/wasm"
        }
    }), {}).then(output => {
        console.log(output);
    }).catch(reason => {
        console.log(reason);
    });
</script>

Upvotes: 1

Views: 3716

Answers (2)

Lucio Paiva
Lucio Paiva

Reputation: 20816

You can still use fetch() as long as you switch to using instantiate() instead of instantiateStreaming(), since the former does not care about MIME types, while the latter does. Example:

const response = await fetch("relative/path/to/file.wasm");
const buffer = await response.arrayBuffer();
const output = await WebAssembly.instantiate(buffer);
console.log(output);

Upvotes: 0

James
James

Reputation: 680

I used XMLHTTPRequest instead to get around the issue.

Upvotes: 0

Related Questions