We’ve just upgraded our site to Gatsby 4 and it builds and deploys without issue on our staging instance on Gatsby Cloud. On deploying to Netlify today the build fails with the following errors:
1:01:19 PM: The function “__SSR” is larger than the 50MB limit. Please consider reducing it.
1:01:20 PM: The function “__DSG” is larger than the 50MB limit. Please consider reducing it.
Our site is large and as far as I know we have no control over the contents of these .zip files. How we resolve this issue? We use Gatsby functions so can’t disable all Gatsby functions.
You’d have to work to reduce the number of pages that go in the DSG bundle or reduce the overhead used by some Node Modules. If you’re having any other resources like images, it’s worth stripping those off too.
There’s this guide for Next.js Functions:
This file has been truncated.
## Troubleshooting large functions
You may see an error about generated functions being too large. This is because when deploying your site it is packaged
into a zipfile, which is limited by AWS to 50MB in size. There are two possible causes for this, each with its own
solution. The list of largest files shown in the build logs will help you see what the cause is.
- **Large dependencies** This is the most common cause of the problem. Some node modules are very large, mostly those
that include native modules. Examples include `electron` and `chromium`. The function bundler is usually able to find
out which modules are actually used by your code, but sometimes it will incorrectly include unneeded modules. If this
is the case, you can either remove the module from your dependencies if you installed it yourself, or exclude it
manually by adding something like this to your `netlify.toml`, changing the value according to the problematic module.
The `!` at the beginning of the module path indicates that it should be excluded:
included_files = ["!node_modules/a-large-module/**/*"]
If you do need large modules at runtime (e.g. if you are running Puppeteer in a Next API route), consider changing to
a Netlify function which will have less overhead than the equivalent Next.js function.
which could be relevant to Gatsby too.