JavaScript heap out of memory while packaging functions

I’ve seen a large amount of this error:
“FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory”
in the forums.

Many of which say “downgrade this” or “tweak that”. And there’s some suggestions of increasing the memory limit for builds. (this is honestly just ignoring the issue)

I have a very complicated project that does a bunch of funny things with module imports, and it really causes problems with the @vercel/nft static analyzer.

The thing is… my project is already properly bundled. I’m rather horrified that it’s getting bundled again, and with random settings i can’t control.

Is there some way i can ditch the “zip-it-and-ship-it” tool that’s used internally and supply my own?
It’s honestly not hard to zip a folder with a decent node.js module inside.

Thanks.

Please share a site to check.

Thanks for engaging on the thread. I’m going to share some links to build deploys, assuming you can check the logs and maybe download build aretfacts on your end if you wish. Or i can share more info.

Re: this build:

Locally, when i run npx netlify serve, it fails with “JavaScript heap out of memory”.
On the logs on netlify, you’ll find a different error:

11:29:32 PM: Packaging Functions from netlify/functions directory:
11:29:32 PM:  - server.mjs
11:29:32 PM: ​
11:29:54 PM: ✘ [ERROR] Could not resolve "../config"
11:29:54 PM:     core/sandman.ts:3:24:

11:29:54 PM:       3 │ import * as Config from "../config";

what’s interesting about this error is that this file is part of a github submodule that is included in the repo folders, but isn’t supposed to be reference by my code. My own bundled processes run fine.

The change causing this issue i suspect is this:
-const queryRe = //mods/([a-zA-Z0-9]+)/([0-9]+)/(.*)/;
+const src_root = process.env.SRC_ROOT || “mods”
+const queryRe = /${src_root}/([a-zA-Z0-9]+)/([0-9]+)/(.*);

This regular expression is used in a rollup plugin that runs at runtime in the backend. This is not simple stuff to debug.

A bit beside the point, but in my case I expect I the env var may have been empty. This is what caused a large scan of the sourcecode by the static analyzer.

Your setup seems to be non-standard, or in other words, unique. Mind sharing what exactly you’re doing and explain your setup? If would be great if you can also share a reproduction repo.

I unfortunately don’t have the resources to devote to creating such a thing as a minimal repro step.

But I can try to describe the key configuration that causes problems:

I think anyone who tries to do dynamic imports capable of importing any files in their repo, or that doesn’t but isn’t so obviously so, can encounter this issue.

Sounds like some customers encounter similar issues with popular npm modules. I can’t comment on those cases, except that i’m not surprised.

I’m hoping someone having a similar issue can recognize their use case i similar to mine can unblock themseleves.

or someone at netlfiy can offer a simpler pass-through for generating your own server.zip, in case of non-standard configurations.

You can create your own zip and deploy it via the API: Get started with the Netlify API | Netlify Docs. But that’s only useful when you deploy your entire site via API or separate the function from the site to be deployed separately.