EasyQRCodeJS-NodeJS
EasyQRCodeJS-NodeJS copied to clipboard
Canvas dependency is too big to deploy on Vercel
As you can see from the screenshot, canvas alone is taking up more than 90% of the allowed size of Vercel's serverless functions. Would suggest moving to something more lightweight like: https://www.npmjs.com/package/@napi-rs/canvas
Vercel error
My Serverless function
import { NextApiRequest, NextApiResponse } from 'next'
import nextConnect from 'next-connect'
import QRCode from 'easyqrcodejs-nodejs'
const handler = nextConnect().get(async (req: NextApiRequest, res: NextApiResponse) => {
const options = {
width: 400,
height: 400,
text: 'https://example.com',
dotScale: 0.9,
}
const qrcode = new QRCode(options)
const base64Data = (await qrcode.toDataURL()).replace('data:image/png;base64,', '')
const img = Buffer.from(base64Data, 'base64')
res.setHeader('Content-Type', 'image/png')
res.setHeader('Content-Length', img.length)
res.send(img)
})
export default handler
Completely agree, same issue for deploying on any lambda, Canvas alone take all the free space