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

Hey folks, I'm trying to get a Wasm library to work in a Pages function, but I'm having the hardest time instantiating it. At first I was fetching the .wasm binary to instantiate, but someone in #pages-help told me it had to be bundled within the _worker.js script. Okay, now it's a UInt8Array directly in the _worker.js script but I still get this error. Is there more information on how the wasm binary should be bundled? Is it a specific format that will make the CF worker accept it?
9 Replies
zegevlier
zegevlierā€¢5mo ago
It should be imported, like in this example: https://developers.cloudflare.com/workers/runtime-apis/webassembly/javascript/#use-from-javascript Anything else will not work. You cannot create a WebAssembly object from anything that could chance at runtime
xeon06
xeon06ā€¢5mo ago
How does that get bundled in the end? I am using Astro here so maybe that's my problem, Vite can't bundle my wasm as expected Is there any more info on the format that this is to be expected to be in for the upload? I could always create a vite plugin I imagine wrangler is doing the bundling directly in that instance? Ah yes scrolling up reveals that
zegevlier
zegevlierā€¢5mo ago
I believe they would be uploaded seperately (so the .wasm binary file would be uploaded, along with the code), although I'm having a hard time finding documentation for it. I'm sure the requests are made somewhere in the wrangler source (https://github.com/cloudflare/workers-sdk), but I wouldn't be able to tell you where.
xeon06
xeon06ā€¢5mo ago
All good I appreciate it. Push comes to shove I can always try bundling a minimal example with wrangler and see what comes out. Thanks! It turns out the Astro adapter has already done the work of the vite plugin for this and it works great if you configure it properly šŸ™ƒ I am curious about the impact of this external wasm file on bundle size though. The wrangler deploy --dry run option doesn't seem to take it into consideration, although it does show it in an "additional modules" table?
xeon06
xeon06ā€¢5mo ago
No description
xeon06
xeon06ā€¢5mo ago
Ah I tried taking it out of the bundle and it does count the file in the table in that total
zegevlier
zegevlierā€¢5mo ago
Yea, it's definitely something to consider when using wasm. If the entire worker goes over 1mb you'll have longer cold start times
xeon06
xeon06ā€¢5mo ago
Ah, I had read that the bigger the size the slower the cold start but is there like a different code path taken > 1 mb?
zegevlier
zegevlierā€¢5mo ago
Yea. Above 1mb they are not stored at every datacenter around the world, lower they are (on paid plan at least)
Want results from more Discord servers?
Add your server
More Posts
Workers a good solution to adding GeoCookies?Hey everyone! I've got a client that's asking us to add cookies that identify geolocation before itImport json file as a Table to D1Hi, I created a D1. How can I import some json files to the database? What do I need to configure?DKIM signing emails from worker.Using a worker setup like: https://developers.cloudflare.com/email-routing/email-workers/send-email-Unable to transfer domain name managed by Cloudflare to Cloudflare?It says Domain Registration: Unknown (Donuts-NC) but the transfer link is grayed out. Says to wait aCloudflare doesn't send response to client on proxied record using CaddyI am currently using Cloudflare on my domain to hide the IP of my server that uses Caddy as a reversSvelteKit - Failed to load resource: the server responded with a status of 500 ()I have done some changes to my app, and since then I get this error message on CF Pages. Failed to lI need support but I don't even understand the problem to describe itI'm not a dev, I'm a body modification artist. I've had a wordpress based website through 123reg forjust change the method to `PUT` and it'just change the method to `PUT` and it'll work. You'll likely want to add `If-Unmodified-Since` to eRDP via Cloudflared Tunnel is Slow.I am trying to setup Cludflared Tunnel for secure rdp access to a server hosted in Azure. I am usiāŒ [ERROR] Error in ProxyController: Error inside ProxyWorker```ts āœ˜ [ERROR] Error in ProxyController: Error inside ProxyWorker { name: 'Error', mess