Open lecramr opened 4 months ago
Hey there, sorry for not putting up a warning about this issue. You’re not doing anything wrong and I’m planning to propose a fix for this soon (in the Vercel SvelteKit adapter). Here’s why it happens:
The default font is currently not being bundled together in the edge function where @vercel/og is being used. This occurs because the esbuild settings for adapter-vercel does not specify to copy over font files. As a result, your deployment fails when it analyses your bundled code and can’t find the font file.
The demo website from this repository works around this by running pnpm patch @sveltejs/adapter-vercel
and editing the esbuild settings to copy over the .ttf font file and to not rename imported assets with a hash.
Now that esbuild is configured to copy over the font file that @vercel/og requires with the precise name it was given, this package uses a little hack by referencing the asset in an import so that esbuild knows it should copy over the font file.
https://github.com/eltigerchino/svelte-og-image/blob/53704ce19bb7883761545fc18993dbce81a0412f/src/lib/index.ts#L7
Without this, the font file will not get copied over because esbuild doesn’t know about it since the@vercel/og package only references the asset in a URL
constructor (which esbuild does not recognise yet) instead of an import
.
https://github.com/evanw/esbuild/issues/795
In the end this really needs to be fixed in @sveltejs/adapter-vercel (and optionally @vercel/og too but it is not open-sourced). However, I’m currently away from my laptop until next Tuesday.
Just need to wait for https://github.com/sveltejs/kit/pull/11674 to be merged so that it can be used on the edge by specifying at least one font such as https://github.com/eltigerchino/svelte-og-image/blob/main/src/routes/og/%2Bserver.ts
Hey,
first thanks for the library! When I try to deploy my project to Vercel I get following error:
Generation Code I am using is:
Any Ideas what I am doing wrong?