-
Notifications
You must be signed in to change notification settings - Fork 127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[🐛 Bug]: WebAssembly.instantiate(): Wasm code generation disallowed by embedder #704
Comments
I'm running Qwik City on Vercel Edge and I'm using the framework agnostic og-image library https://github.com/fabian-hiller/og-img but I'm running into exactly the same error:
I guess this is a security measure to prevent loading external wasm files? |
Hi @JoepKockelkorn, thank you for the issue 🙂 (and for the nice words regarding the library ❤️) Yes, wasm code generation is not supported in our runtime for security reasons, exactly like in JavaScript where I can see that we don't document this in our docs, I've created an issue for that: cloudflare/cloudflare-docs#13469 I don't think there can be any possible workaround for this either 😓 |
Thanks for your clarification. Security above everything! For the nice words you'll have to thank @dungmidside, I just ran into something similar on Vercel Edge 😉. But I'm sure cloudflare pages is great! Thanks for creating the issue 👍 |
Sorry, I somehow missed that the comment was from a different user 😅🤦 @dungmidside thanks! ❤️ |
@dungmidside @JoepKockelkorn since there isn't really much we can do about this here I would be inclined to close this issue, would that work for you? 🙂 |
Sure! |
Hi @dario-piotrowicz, thanks for your response. I just wonder about this, if cloudflare block wasm code generation, why this worker-og library - which use the same I have another worker that use this library and it worked even it seem use the same import { ImageResponse } from 'workers-og';
export default {
async fetch(req: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
const fontRegular = await fetch('https://cdn.jsdelivr.net/fontsource/fonts/poppins@latest/latin-400-normal.ttf').then((res) =>
res.arrayBuffer()
);
const decodedUrl = req.url.replace(/&/g, '&');
const params = new URLSearchParams(new URL(decodedUrl).search);
const title = params.get('title');
const html = `<div style="">${title}</div>
`;
return new ImageResponse(html, {
width: 1200,
height: 630,
fonts: [
{
name: 'Poppins',
data: fontRegular,
weight: 400,
style: 'normal',
},
],
});
},
}; |
@dungmidside the code you shared imports the wasm modules from local files: https://github.com/kvnang/workers-og/blob/52489a562245fb01f10a38a7a1a523fc03497a1c/packages/workers-og/src/og.ts#L8-L11 So those modules are fine to be initialized, the issue if that the you cannot fetch the wasm modules from some external source (like you did with |
@dario-piotrowicz I used |
@dungmidside yes exactly, you could update the config file to allow for wasm imports or more simply you could just import the wasm using Like I did here for example:
I've also just found out that there's an error page regarding this in the Next.js docs 🙂: https://nextjs.org/docs/messages/edge-dynamic-code-evaluation |
@dario-piotrowicz thanks for your suggestion about import with
I copy import { Resvg, initWasm } from "@resvg/resvg-wasm";
import wasmModule from './index_bg.wasm?module';
// other code
await initWasm(wasmModule); |
@dungmidside the error you shared is an error that should have already been fixed in: #681, which has been shipped as part of the From the PR description it seems like you're on Could you make sure to use |
@dario-piotrowicz it seem work now |
@dungmidside my pleasure, I'm glad we did get to the bottom of it 😄 regarding the limit yeah sorry about that, there's nothing I can really do about it 😓 |
next-on-pages environment related information
System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.1.0: Mon Oct 9 21:27:24 PDT 2023; root:xnu-10002.41.9~6/RELEASE_ARM64_T6000
CPU: (10) arm64 Apple M1 Pro
Memory: 16 GB
Shell: /bin/zsh
Package Manager Used: npm (9.6.7)
Relevant Packages:
@cloudflare/next-on-pages: 1.9.0
vercel: N/A
next: N/A
Description
Hi everyone,
Thanks for this awesome library.
Currently I have an NextJS app that deployed on Cloudflare pages, my app have an API route for generate OG Image in PNG format.
I use
satori
for generate SVG data and@resvg/resvg-wasm
for convert SVG to PNG format.Here is my code at
pages/api/og.tsx
In local, it work as expect, but when I deploy to Cloudflare pages, but when I access the API, function
initWasm
keep throw error with messageIs there anyone know the solution for this ?
Live URL: https://008c691d.personal-doh.pages.dev/api/og?title=xyz
Reproduction
Pages Deployment Method
Pages CI (GitHub/GitLab integration)
Pages Deployment ID
https://008c691d.personal-doh.pages.dev
Additional Information
No response
Would you like to help?
The text was updated successfully, but these errors were encountered: