I am unable to get WASM to work on Vercel. I have a normal Sveltekit project, with a Rust library inside. I’m using wasm-pack to compile and optimize it. This is the current way I’m using it inside the main +page.svelte
:
import { onMount } from 'svelte';
let lib: typeof import('wasm-lib');
onMount(async () => {
lib = await import('wasm-lib');
await lib.default();
let largeArray = new Int32Array(1e6).fill(1);
console.log(lib.sum(largeArray));
});
And it does indeed work when ran locally, using bun run dev
, however, not on Vercel. The error messages I am getting are:
using deprecated parameters for the initialization function; pass a single object instead
GET https://dcutils.vercel.app/_app/immutable/chunks/wasm_lib_bg.wasm 404 (Not Found)
`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:
TypeError: Failed to execute 'compile' on 'WebAssembly': HTTP status code is not ok
Uncaught (in promise) CompileError: WebAssembly.instantiate(): expected magic word 00 61 73 6d, found 4e 6f 74 20 @+0