cloudflare/next-on-pages

[๐Ÿ› Bug]: `@vercel/og` doesn't work

Opened this issue ยท 22 comments

w00fz commented

I'm having issues getting my project to successfully deploy on Cloudflare because I am relying on a dependency (@vercel/og) which uses satori/wasm.

The Vercel building process goes fine but when next-on-pages gets to build the final worker bundle , esbuild fails with error:

โœ˜ [ERROR] Could not resolve "/wasm/wasm_53adb396180a95eb122a0218c93e3d6474b1a27e.wasm"

Any idea on how this could get resolved?

We don't currently support Wasm in Pages Functions, but we hope to add this soon. We'll update this issue when we get around to this.

Is there any workaround/update?

Note

This issue is blocked by: #202 and cloudflare/pages-plugins#30

Most likely solving the two issues above should in turn also solve this one

Ahh okay. Thanks :)

No problem, sorry this is taking so long ๐Ÿ˜“, I'll definitely look into #202 soon (likely this or next week), I'll try to also get the pages-plugins one solved soon-ish as well ๐Ÿ™‚

#202 has been resolved, so now it should just be the pages-plugin one that needs addressing ๐Ÿ™‚

Sorry I misunderstood things, we don't necessarily want to force developers to use the vercel-og pages plugin, so that is not blocking this

@vercel/og anyways isn't yet currently working on next-on-pages, so that is indeed something we need to fix

in any case I'm going to update the issue title as it is now unrelated to wasm (and also that it contains @vercel/og so that people having troubles with it can more easily notice this issue)

Have been following a couple of different issue thread but the current stat is unclear to me. At the moment, is there any workaround or way to use either @vercel/og or @cloudflare/pages-plugin-vercel-og/api?

Hi @lucaswalter, no I'm sorry, I had a quick look some time ago but haven't dug much into it since, so it's still unresolved ๐Ÿ˜“

Thanks for the update @dario-piotrowicz โ€” Do you know what the main blocker is for this? I would like to make use of this for my projection on Pages, but am not sure where else to follow for status updates.

@lucaswalter as far I know there actually isn't a real blocker, it's just a matter of finding the time to dig into what the issue with vercel/og actually is.

it's been a few weeks so I don't remember precisely, but I think there was something Vercel does that we need to reverse engineer and fix/adapt to our runtime.

Sorry, I haven't put too much priority into this since being related to a Vercel library so it's not a core issue with Next per se, I'll try to dig into this soon (this or next week) ๐Ÿ™‡

PS: I'll post status updates here

Understood, thanks a ton @dario-piotrowicz

No problem @lucaswalter ๐Ÿ™‚

Check out #325 we're very close! ๐Ÿ˜„ (feel free to try out the next-on-pages prerelease and let me know if it works for you if you want)

Thanks @dario-piotrowicz โ€” Will keep following along

@lucaswalter I've merged the PR so @vercel/og should now work ๐Ÿ™‚

See the example I added in the PR's description: https://a9aeda25.next-on-pages-test-5h3.pages.dev/

As you can see (third link) now @vercel/og should work, unfortunately it seems like in certain cases
we can get an error (second link), I believe that that is a runtime bug and I will check with the runtime team about it,
so let's keep this issue open a bit longer, so I will let you know here when that is also sorted out

(PS: you can check in the latest beta release if @vercel/og works for your use case)

w00fz commented

This is awesome, thank you!

I'm closing the issue since I could not reproduce it using the demo app anymore (and also the deployment link above seems to be working totally fine)

I did try to re-deploy the app multiple times (since in the past I saw this happen sporadically on deployments of the same app), none of the deployment presented the issue:

So hopefully the problem should have completely gone away ๐Ÿ™‚๐Ÿคž

Hey unfortunately I am facing a very similar (if not the same) issue.

npx next build runs perfectly fine.. I suspect @cloudflare/next-on-pages is to blame..

โ–ฒ  Traced Next.js server files in: 274.752ms
โ–ฒ  Created all serverless functions in: 626.293ms
โ–ฒ  Collected static files (public/, static/, .next/static): 4.955ms
โ–ฒ  Build Completed in .vercel/output [12s]
โšก๏ธ Completed `npx vercel build`.
โšก๏ธ Unexpected error: ENOENT: no such file or directory, copyfile '/Users/tomaspietravallo/Documents/PROJECT/.vercel/output/functions/api/og.func/wasm/wasm_ef4866ecae192fd87727067cf2c0c0cf9fb8b020.wasm' -> '/Users/tomaspietravallo/Documents/PROJECT/.vercel/output/static/_worker.js/__next-on-pages-dist__/wasm/wasm_ef4866ecae192fd87727067cf2c0c0cf9fb8b020.wasm'

I am trying to use @vercel/og to generate images for og

import React from "react";
import { ImageResponse } from "@cloudflare/pages-plugin-vercel-og/api";
import type { NextRequest } from "next/server";

export const runtime = 'edge';

export async function GET(request: NextRequest){
  return new ImageResponse(
    <Component/>,
    {
      width: 800,
      height: 400,
      status: 200,
      debug: false,
    }
  ) as Response;
};

This happens when trying to use ImageResponse from either @cloudflare/pages-plugin-vercel-og/api (like the docs suggest), @vercel/og or next/og

Ps the second link on the deployment you shared @dario-piotrowicz is not working "Example of vercel/og usage (which relies on wasm)" returns "internal server error" for me

Ps the second link on the deployment you shared @dario-piotrowicz is not working "Example of vercel/og usage (which relies on wasm)" returns "internal server error" for me

@tomaspietravallo Thanks a bunch for letting me know ๐Ÿ™
(PS: when I wrote my comment above with all those deployments all of them worked fine including the one you shared... now I also go get the internal server errors ๐Ÿ˜“)

This issue is quite bothersome as it has to be something runtime related... and it looks like the issue appears and disappears... making it very difficult to understand what's going wrong! ๐Ÿ˜“
I'll have to try to see if anything can be done regarding it ๐Ÿ˜“

Hey unfortunately I am facing a very similar (if not the same) issue.

npx next build runs perfectly fine.. I suspect @cloudflare/next-on-pages is to blame..

Yes I'd say that your issue is not the same... could you possibly create a new issue? with also a minimal reproduction? ๐Ÿ™

I'm sure they did work. I hope you are able to find the cause, I'll be around to run any tests you might need help with.

For whatever reason the custom font example on your site DOES work (im assuming old deployment/version) https://17cb6ed0.next-apps-for-testing.pages.dev/api/og-custom

I'll open a new issue, hopefully I'll get a minimal example ready by tomorrow