CompileError: WebAssembly.instantiate(): Wasm code generation disallowed by embedder

Hey folks, I'm trying to run a wasm file compiled by emscripten on CF workers. It's working fine locally, but when I try it in production I get:
failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): Wasm code generation disallowed by embedder
failed to asynchronously prepare wasm: CompileError: WebAssembly.instantiate(): Wasm code generation disallowed by embedder
This page seems to indicate that WebAssembly.instantiate should work, am I missing something? https://developers.cloudflare.com/workers/runtime-apis/webassembly/
WebAssembly (Wasm) · Cloudflare Workers docs
Execute code written in a language other than JavaScript or write an entire Cloudflare Worker in Rust.
6 Replies
kian
kian11mo ago
The module can't be inlined as a buffer, it needs to be uploaded as a separate .wasm file
xeon06
xeon06OP11mo ago
Thanks for taking the time to answer. It is; the emscripten glue is fetching it The error happens on instantiate, but the fetch code before works without error:
function Ea(a) {
return y || "function" != typeof fetch ? Promise.resolve().then(function() {
return Da(a)
}) : fetch(a, {
credentials: "same-origin"
}).then(function(b) {
if (!b.ok) throw "failed to load wasm binary file at '" + a + "'";
return b.arrayBuffer()
}).catch(function() {
return Da(a)
})
}

function Fa(a, b, c) {
return Ea(a).then(function(d) {
return WebAssembly.instantiate(d, b)
}).then(function(d) {
return d
}).then(c, function(d) {
w("failed to asynchronously prepare wasm: " + d);
z(d)
})
}
function Ea(a) {
return y || "function" != typeof fetch ? Promise.resolve().then(function() {
return Da(a)
}) : fetch(a, {
credentials: "same-origin"
}).then(function(b) {
if (!b.ok) throw "failed to load wasm binary file at '" + a + "'";
return b.arrayBuffer()
}).catch(function() {
return Da(a)
})
}

function Fa(a, b, c) {
return Ea(a).then(function(d) {
return WebAssembly.instantiate(d, b)
}).then(function(d) {
return d
}).then(c, function(d) {
w("failed to asynchronously prepare wasm: " + d);
z(d)
})
}
kian
kian11mo ago
Fetch as in from a URL? That's basically the same thing as loading it as a Buffer.
xeon06
xeon06OP11mo ago
Yeah fetched from a URL How should I proceed? Does it need to be like bundled in? My understanding was that .wasm code is typically fetched over the network, and I was thinking this would help with worker bundle size given the wasm file is almost 1mb itself
kian
kian11mo ago
It needs to be bundled
xeon06
xeon06OP11mo ago
Sorry I'm slightly confused, above when you said "it needs to be uploaded as a separate .wasm file", that's not contrary to the idea of bundling it? I assume something like this https://vitejs.dev/guide/features#webassembly which will include it in the bundle. I also realized that paid is now 10mb. I'll give that a go, thanks for the help.
Want results from more Discord servers?
Add your server