The function "XXX" is larger than the 50MB limit - even though zip is only 22.7MB

Hi there. I’m struggling to deploy a site. One of the edge functions is failing with the following error:

The function "LISTING-IMAGE-GENERATE" is larger than the 50MB limit. Please consider reducing it.

The function uses node-canvas so I know it can be problematic in terms of file-size. However, I’ve been testing and building locally to see if I can reduce the zip size and I’ve been able to reduce it to 22.7MB, but for some reason I’m still getting the error above.

Am I right in saying that the command below (when run locally) will give me a true representation of the build output on production?

npx netlify-cli build --context deploy-preview

Yes, except CLI cannot emulate platform-specific dependencies. So the exact true representation would be to use Netlify CLI on a Ubuntu machine (or Netlify Docker image).

So I’d assume that it somehow goes over the 50 MB limit when building on Ubuntu.

Thanks - are there any guides for custom specifying the exact dependencies an edge function will build with? I added a local package.json file to the function but when I built the project it didn’t seem to respect what was in that file - it instead pulled in dependencies from the main (root) package.json as well.

Are you talking about Edge Functions or Lambda Functions? They’re 2 different things. Because you say package.json, I’m assuming you’re talking about the latter.

Netlify only installs dependencies from the root package.json. I wonder why you need to specify different versions of dependencies for your project vs functions.

You can probably do something like cd functions-dir npm ito install everything there, which theoretically should work, however it’s untested and not a recommended way.

Ah yes fair point - I’m referring to lambda functions.

Point noted regarding netlify only installing dependencies from the root package.json.

The key issue I’m having at the moment is that I need to be able to install a custom built version of node-canvas but I can’t seem to work out how to reference that. Should I take ‘canvas’ out of the package.json and instead create a node_modules folder directly in the function folder and place my custom canvas build in there? Or should I do that another way?

Hard to say, without more details. Perhaps you could link us to your deploy logs so in our system, so we could look at them and try to advise? (our staff can see most URL’s that you can in our UI; deploy logs are included).

I understand you also use the CLI, but we can’t see the output of that - which we can see from our CI system :wink:

Hey absolutely. Here’s the URL of one of the failed deploys:

As noted though, the main thing I’m trying to work out is if I’ve created a custom build of a node module (node-canvas in this case), what do I need to do to make sure that that version is the one packaged up and included with the lambda function vs the build sequence simply building the default npm version?

You can store the binary in your repo and use:

to include that in your bundle. Then, you can import that one instead of importing the one from npm.

Thanks, I’ll take a look.