Functions failing to deploy despite local bundle being smaller than 50mb

shopify-api-node, one of the dependencies used in my Netlify functions uses dynamic imports and hence produces MODULE_NOT_FOUND errors.

To fix this, I added it to external_node_modules like so:

[functions]
  node_bundler = "esbuild"
  directory = "functions"
  external_node_modules = ["shopify-api-node"]

but I’m facing a Request must be smaller than 69905067 bytes for the CreateFunction operation error.
When I bundle my functions locally using yarn netlify functions:build --src functions, the .zip files produced are nowhere close to the 50mb limit. The largest is 17mb.

Why am I facing this error?

That’s unlikely. We’ve received multiple such requests this week, but all of those has touched the 50 MB mark:

https://answers.netlify.com/t/cannot-deploy-site-due-to-too-large-function-node-v16-12/46022

I’d be tempted to test your project locally and try to reproduce the issue. Could you share your repo?

Unfortunately I am not able to share the repo.
What’s the proper way to build functions locally? Perhaps the command I am using: yarn netlify functions:build --src functions is not faithful to the way Netlify bundles functions for production?

Below are the file sizes for the bundles generated by the command above.
image

It’s worth nothing that even if I omit
external_node_modules = ["shopify-api-node"] from my netlify.toml the bundles remain the same size.

That should do it. But you could also try to run entire build to see if that produces a different result by any chance. Try netlify build.

Make sure you’re using the latest version of CLI.

If the size stays same, try deploying using the CLI with netlify deploy --prod.

netlify -v produces the following output: netlify-cli/6.14.1 win32-x64 node-v14.18.1

The bundles found in .netlify/functions after running netlify build are slightly larger, but individually still well below 50mb.

image

Running netlify deploy --prod produced a successful deploy with the following warning:

 »   Warning: Modules with native dependencies
 »
 »   - [redacted]
 »   - [redacted]
 »
 »   The serverless functions above use Node.js modules with native dependencies, which
 »   must be installed on a system with the same architecture as the function runtime. A
 »   mismatch in the system and runtime may lead to errors when invoking your functions.
 »   To ensure your functions work as expected, we recommend using continuous deployment
 »   instead of manual deployment.
 »
 »   For more information, visit https://ntl.fyi/cli-native-modules.

In fact, the functions are broken when deployed this way.

This is because you’re using Windows, but deploying on Linux servers that AWS uses, I believe.

Well, unfortunately without a reproduction, I can’t confirm this and can’t comment on any possible solutions. While the Request must be smaller than 69905067 bytes for the CreateFunction operation error is common, I’ve never seen it happen for functions that are less than 50 MB in size.

I am able to reproduce this with the following files.
I PMed you a reproduction repo for your convenience.

# netlify.toml
[build.environment]
  NODE_VERSION = "12.22.7"

[functions]
  node_bundler = "esbuild"
  directory = "functions"
  external_node_modules = ["shopify-api-node"]

// functions/test.ts
import { loadImage, createCanvas } from "canvas";
import Shopify from "shopify-api-node";

console.log(loadImage, createCanvas, Shopify);

Awesome, I’ll give this a go and see what’s happening. If it’s a bug, I’d pass it on to the developers and keep you in the loop.

1 Like

I just checked it and built it locally using netlify-cli on Ubuntu and this is what I got:

So yes, when building on Linux, the size is going over 50 MB probably because of the native dependencies that CLI warned about before.

Could you kindly check what the bundle size is when you remove shopify-api-node from netlify.toml and test.ts?

I reckon that the canvas package is increasing the size dangerously close to the 50 MB limit and then shopify-api-node is pushing it over the edge.

51.9 MB, not too different, I’m afraid.

That’s quite bizarre. I have a few functions which use the canvas package and they all deploy successfully.
I imagine there is some leeway allowed on the 50 MB and it’s only when I include the shopify-api-node package that I go over.

I wonder if its something I’m misconfiguring that’s causing the canvas package to bloat the bundle so much.
I know that quite a few users here use the canvas package with Netlify functions and I have seen none of them report this.

Sure well, you could try to use WSL or run Ubuntu in a virtual machine to debug this, but that’s what I could see.