Can I use Satori outside vercel? Getting "Satori is not a function"
Unanswered
Alligator mississippiensis posted this in #help-forum
Alligator mississippiensisOP
New dev here. I'm trying to use Satori but continually getting an error saying "satori is not a function". I've made sure it's installed and properly imported. I've been trying to get help from ChatGPT but no luck. For context, this is a React app with Express server. Satori is installed on my backend and I'm also using Babel (if that's relevant). Here is my code for generating the image. If that's not enough info, happy to share more just let me know what you need
const satori = require('satori');
// const sharp = require('sharp');
const React = require('react');
async function generateProductImage(product) {
console.log('Generating image for product:', product);
const productImageSrc = product.image;
console.log('Product image source:', productImageSrc);
try{
const svg = await satori(
<div style={{ display: 'flex', backgroundColor: '#fff', width: '600px', height: '400px' }}>
{productImageSrc && <img src={productImageSrc} style={{ width: '200px', height: '200px' }} alt={product.title} />}
<div style={{ marginLeft: '20px' }}>
<h3 style={{ fontSize: '24px', color: '#333' }}>{product.title}</h3>
<p style={{ fontSize: '16px', color: '#666' }}>{product.description}</p>
</div>
</div>,
{ width: 600, height: 400 }
);
console.log('Generated SVG:', svg);
return svg;
} catch (error) {
console.error('Error in generating SVG with Satori:', error);
throw error; // Rethrow the error to be handled in the calling function
}
// const pngBuffer = await sharp(Buffer.from(svg)).png().toBuffer();
// const pngBase64 = pngBuffer.toString('base64');
// return pngBase64;
}
module.exports = generateProductImage;