EasyQRCodeJS-NodeJS icon indicating copy to clipboard operation
EasyQRCodeJS-NodeJS copied to clipboard

Canvas dependency is too big to deploy on Vercel

Open kdubb1337 opened this issue 2 years ago • 1 comments

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

CleanShot 2023-02-09 at 21 12 45

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

kdubb1337 avatar Feb 10 '23 02:02 kdubb1337

Completely agree, same issue for deploying on any lambda, Canvas alone take all the free space

0xAnthony avatar Nov 30 '23 11:11 0xAnthony