Node Canvas on Vercel Serverless Function - The Serverless Function exceeds the maximum size limit of 50mb
Asked Answered
K

1

7

I'm generating images on the server based on data users send to the API route I have in Next.js using the canvas package.

It's working great, but I am unable to deploy the project to Vercel as the canvas dependency is too big (44.9 MB compressed size):

Warning: Max serverless function size of 50 MB compressed or 250 MB uncompressed reached
Serverless Function's page: api/generate-mint-signature-for-character.js
Large Dependencies                         Uncompressed size  Compressed size
application/node_modules/canvas                       172 MB          44.9 MB
application/public/cozy-people-asset-pack            7.37 MB           5.5 MB
application/node_modules/next                        4.42 MB          1.28 MB
Max serverless function size was exceeded for 1 function
Created all serverless functions in: 42.626s
Collected static files (public/, static/, .next/static): 240.385ms
Build Completed in /vercel/output [4m]
Failed to process build result for "api/generate-mint-signature-for-character". Data: {"type":"Lambda"}.
Error: The Serverless Function "api/generate-mint-signature-for-character" is 53.97mb which exceeds the maximum size limit of 50mb. Learn More: https://vercel.link/serverless-function-size

Is there any way I can trim down this dependency size or only import the parts of the package I need in this API route?

Kucera answered 25/9, 2022 at 3:28 Comment(0)
K
8

I solved this by replacing the canvas dependency with @napi-rs/canvas.

Kucera answered 25/9, 2022 at 5:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.