-
Notifications
You must be signed in to change notification settings - Fork 26
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] Unable use @vercel/og with OpenNext #133
Comments
Hi @gregavola |
No I didn't sadly. |
Prepared reproduction repo as requested: https://github.com/kpyszkowski/opennextjs-cloudflare-vercel-og-bug-repro |
The error
is at var fontData = fs.readFileSync(fileURLToPath(join(import.meta.url, "../noto-sans-v27-latin-regular.ttf")));
var yoga_wasm = fs.readFileSync(fileURLToPath(join(import.meta.url, "../yoga.wasm")));
var resvg_wasm = fs.readFileSync(fileURLToPath(join(import.meta.url, "../resvg.wasm"))); Because |
I will not have time to work on this in the next few days so adding the steps to fix if someone has time to look at this before. Use the edge version rather than the node version of og. This should be done before bundling (after that the required file is imported). We should replace To avoid having to search all the source code, we can first look for We can use ast-grep for that, i.e.
Patch the edge code The edge code looks like: var initializedResvg = initWasm(resvg_wasm);
var initializedYoga = initYoga(yoga_wasm).then((yoga2) => Rl(yoga2));
var fallbackFont = fetch(new URL("./noto-sans-v27-latin-regular.ttf", import.meta.url)).then((res) => res.arrayBuffer());
var ImageResponse = class extends Response {
constructor(element, options = {}) {
const result = new ReadableStream({
async start(controller) {
await initializedYoga;
await initializedResvg;
const fontData = await fallbackFont; Using ast-grep, we should init the fallbackFont with something like: var fallbackFont = getOgFallbackFont(); where Add a test Add a route in i.e. import { ImageResponse } from "next/og";
export async function GET(request: Request) {
try {
const { searchParams } = new URL(request.url);
return new ImageResponse(
(
<div
style={{
backgroundColor: "black",
backgroundSize: "150px 150px",
height: "100%",
width: "100%",
display: "flex",
textAlign: "center",
alignItems: "center",
justifyContent: "center",
flexDirection: "column",
flexWrap: "nowrap",
}}
>
<div
style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
justifyItems: "center",
}}
>
<img
alt="Vercel"
height={200}
src="data:image/svg+xml,%3Csvg width='116' height='100' fill='white' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M57.5 0L115 100H0L57.5 0z' /%3E%3C/svg%3E"
style={{ margin: "0 30px" }}
width={232}
/>
</div>
<div
style={{
fontSize: 60,
fontStyle: "normal",
letterSpacing: "-0.025em",
color: "white",
marginTop: 30,
padding: "0 120px",
lineHeight: 1.4,
whiteSpace: "pre-wrap",
}}
>
'next/og'
</div>
</div>
),
{
width: 1200,
height: 630,
}
);
} catch (e: any) {
return new Response("Failed to generate the image", {
status: 500,
});
}
} |
This was merged into main, thanks @james-elicx |
Describe the bug
When I try to add
@vercel/og
to the project, it compiles, but provides this as an error:stack:
I've also tried
worker-og
and I get:Even if I try to webAssembly:
I get: Attempted import error: './resvg-LFIOYO65.wasm' does not contain a default export (imported as 'fy').
Steps to reproduce
browser
Expected behavior
I would expect the image to render on the apge.
@opennextjs/cloudflare version
0.2.1
Node.js version
18.x
Wrangler version
3.80
next info output
Additional context
No response
The text was updated successfully, but these errors were encountered: