You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Get error message (Error: Cannot use read from $app/server in /og.png when using @sveltejs/adapter-cloudflare. Please ensure that your adapter is up to date and supports this feature) when building for cloudflare-pages adapter though it says it supports all sveltekit features in the docs,
Reproduction
import type { RequestHandler } from '@sveltejs/kit';
import { error } from '@sveltejs/kit';
import satori from 'satori';
import { Resvg } from '@resvg/resvg-js';
import { html as toReactNode } from 'satori-html';
import { render } from 'svelte/server';
import OgCard from './OgCard.svelte';
import NotoSans from './NotoSans-Regular.ttf';
import { read } from '$app/server';
const fontData = read(NotoSans).arrayBuffer();
const width = 1200;
const height = 648;
const generateOgImage = async (message: string) => {
const { body } = render(OgCard, { props: { message } });
const element = toReactNode(`${body}<style>
div {
font-family: 'Noto Sans';
display: flex;
flex-direction: column;
font-size: 50px;
background-color: white;
height: 100%;
width: 100%;
align-items: center;
justify-content: center;
}
</style>`);
const svg = await satori(element, {
fonts: [
{
name: 'Noto Sans',
data: await fontData,
style: 'normal'
}
],
height,
width
});
const resvg = new Resvg(svg, {
fitTo: {
mode: 'width',
value: width
}
});
return resvg.render().asPng();
};
export const GET: RequestHandler = async ({ url }) => {
try {
const message = url.searchParams.get('message');
if (!message) {
throw error(400, 'Missing required parameters');
}
const imageBuffer = await generateOgImage(message);
return new Response(imageBuffer, {
headers: {
'content-type': 'image/png',
'cache-control': 'public, max-age=604800, immutable'
}
});
} catch (e) {
console.error('Error generating OG image:', e);
throw error(500, 'Failed to generate image');
}
};
### Logs
```Shell
vite v6.0.6 building SSR bundle for production...
✓ 5735 modules transformed.
node:internal/event_target:1101
process.nextTick(() => { throw err; });
^
Error: Cannot use `read` from `$app/server` in /og.png when using @sveltejs/adapter-cloudflare. Please ensure that your adapter is up to date and supports this feature.
at check_feature (file:///path/to/project/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_@types+node@_qesdia25kriwukttr6lzpklpsa/node_modules/@sveltejs/kit/src/utils/features.js:18:11)
at analyse (file:///path/to/project/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_@types+node@_qesdia25kriwukttr6lzpklpsa/node_modules/@sveltejs/kit/src/core/postbuild/analyse.js:130:5)
at async MessagePort.<anonymous> (file:///path/to/project/node_modules/.pnpm/@[email protected]_@[email protected][email protected][email protected]_@types+node@_qesdia25kriwukttr6lzpklpsa/node_modules/@sveltejs/kit/src/utils/fork.js:23:16)
Node.js v23.3.0
Describe the bug
Get error message (Error: Cannot use
read
from$app/server
in /og.png when using @sveltejs/adapter-cloudflare. Please ensure that your adapter is up to date and supports this feature) when building for cloudflare-pages adapter though it says it supports all sveltekit features in the docs,Reproduction
System Info
Severity
annoyance
Additional Information
No response
The text was updated successfully, but these errors were encountered: