Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Large project builds break memory limits on vercel/netlify #4795

Closed
Axeldeblen opened this issue May 2, 2022 · 5 comments
Closed

Large project builds break memory limits on vercel/netlify #4795

Axeldeblen opened this issue May 2, 2022 · 5 comments
Labels

Comments

@Axeldeblen
Copy link

Axeldeblen commented May 2, 2022

Describe the bug

When building large projects on vercel/netlify sveltekit builds fails due to exceeding build memory allocations.

I believe this issue is related to vite/esbuild - kit maintainers if you feel I should post the issue elsewhere please let me know but I thought it would be best to make the issue known here first.

Context

We have migrated our codebase to sveltekit a long time ago and have been loving it. In the last few months I created a branch to upgrade our core svelte packages to the latest versions. Everything worked locally but I kept running into vague esbuild errors with every deploy to Vercel. After experimenting with many different sveltekit, esbuild and vite configs I could not get our project to build successfully on Vercel. I deployed the same code to Netlify and got a memory heap allocation error which narrowed down the cause of the issue.

Problem

I believe the issue is that during the building/bundling esbuild is transforming too many files in parallel and holding too much in memory which results in a javascript heap allocation error.

This error is easily reproducible and I have provided an example repo below which is a fork of sveltejs/realworld. I have simply cloned the src/routes/article folder 2000 times to inflate the build. This causes a build heap error on my local machine and in Vercel. If you lower the number of cloned folders 1000 builds it will build successfully on Vercel.

In our production codebase we are at a point where this error occurs only on Vercel and is blocking us from upgrading. Obviously it is not an option for us to remove routes / components from our project so if we wish to upgrade sveltekit we are forced to consider other bespoke deployment options.

For reference I know Vercel provides 8GB of memory per build.

Solution
Not sure if its possible to implement some kind of progressive build strategy to combat these large builds or perhaps this issue is originating from some internal bug within esbuild package.

Reproduction

https://github.com/Axeldeblen/realworld-big-build

run npm run build locally and deploy to vercl/netlify using default configs

remove 1000 folders and commit to trigger another deploy, it should build successfully on those platforms I have done this in this PR - Axeldeblen/realworld-big-build#1

Logs

local build failure

<--- Last few GCs --->

[60557:0x104905000]   199087 ms: Scavenge (reduce) 4058.9 (4101.9) -> 4058.4 (4101.9) MB, 5.8 / 0.0 ms  (average mu = 0.167, current mu = 0.052) allocation failure
[60557:0x104905000]   199106 ms: Scavenge (reduce) 4060.0 (4099.6) -> 4059.4 (4100.6) MB, 5.1 / 0.0 ms  (average mu = 0.167, current mu = 0.052) allocation failure
[60557:0x104905000]   199127 ms: Scavenge (reduce) 4061.0 (4100.6) -> 4060.5 (4101.6) MB, 7.3 / 0.0 ms  (average mu = 0.167, current mu = 0.052) allocation failure


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory

vercel build failure

vite v2.9.6 building SSR bundle for production...
> The service was stopped
    at /vercel/path0/node_modules/esbuild/lib/main.js:1335:25
    at /vercel/path0/node_modules/esbuild/lib/main.js:666:9
    at Socket.afterClose (/vercel/path0/node_modules/esbuild/lib/main.js:644:7)
    at Socket.emit (events.js:412:35)
    at endReadableNT (internal/streams/readable.js:1334:12)
    at processTicksAndRejections (internal/process/task_queues.js:82:21)
Error: Command "npm run build" exited with 1

netlify

<--- Last few GCs --->
2:48:31 PM: [1460:0x4632bd0]   194829 ms: Scavenge (reduce) 2042.0 (2050.5) -> 2041.2 (2051.5) MB, 13.5 / 0.0 ms  (average mu = 0.258, current mu = 0.264) allocation failure
2:48:31 PM: [1460:0x4632bd0]   194841 ms: Scavenge (reduce) 2042.1 (2050.5) -> 2041.2 (2051.5) MB, 6.8 / 0.0 ms  (average mu = 0.258, current mu = 0.264) allocation failure
2:48:31 PM: [1460:0x4632bd0]   194855 ms: Scavenge (reduce) 2042.1 (2050.5) -> 2041.2 (2051.7) MB, 4.9 / 0.0 ms  (average mu = 0.258, current mu = 0.264) allocation failure
2:48:31 PM: <--- JS stacktrace --->
2:48:31 PM: FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
2:48:31 PM:  1: 0xa3aaf0 node::Abort() [node]
2:48:31 PM:  2: 0x970199 node::FatalError(char const*, char const*) [node]
2:48:31 PM:  3: 0xbba45e v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [node]
2:48:31 PM:  4: 0xbba7d7 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [node]
2:48:31 PM:  5: 0xd769e5  [node]
2:48:31 PM:  6: 0xd7756f  [node]
2:48:31 PM:  7: 0xd853ab v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
2:48:31 PM:  8: 0xd88f6c v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
2:48:31 PM:  9: 0xd4e73d v8::internal::Factory::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [node]
2:48:31 PM: 10: 0xd4a999 v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawArray(int, v8::internal::AllocationType) [node]
2:48:31 PM: 11: 0xd4aa54 v8::internal::FactoryBase<v8::internal::Factory>::NewFixedArrayWithFiller(v8::internal::Handle<v8::internal::Map>, int, v8::internal::Handle<v8::internal::Oddball>, v8::internal::AllocationType) [node]
2:48:31 PM: 12: 0xf914fb v8::internal::OrderedHashTable<v8::internal::OrderedHashSet, 1>::Allocate(v8::internal::Isolate*, int, v8::internal::AllocationType) [node]
2:48:31 PM: 13: 0xf9168f v8::internal::OrderedHashTable<v8::internal::OrderedHashSet, 1>::Rehash(v8::internal::Isolate*, v8::internal::Handle<v8::internal::OrderedHashSet>, int) [node]
2:48:31 PM: 14: 0x1083568 v8::internal::Runtime_SetGrow(int, unsigned long*, v8::internal::Isolate*) [node]
2:48:31 PM: 15: 0x1448e19  [node]
2:48:32 PM: Aborted (core dumped)
2:48:32 PM: npm ERR! code ELIFECYCLE
2:48:32 PM: npm ERR! errno 134
2:48:32 PM: npm ERR! realworld.svelte.dev@1.0.1-next.0 build: `svelte-kit build --verbose`
2:48:32 PM: npm ERR! Exit status 134
2:48:32 PM: npm ERR!
2:48:32 PM: npm ERR! Failed at the realworld.svelte.dev@1.0.1-next.0 build script.
2:48:32 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging outpu

System Info

System:
    OS: macOS 11.5.2
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Memory: 367.55 MB / 16.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.3 - ~/.nvm/versions/node/v14.17.3/bin/node
    Yarn: 1.22.17 - /usr/local/bin/yarn
    npm: 8.1.3 - ~/.nvm/versions/node/v14.17.3/bin/npm
  Browsers:
    Brave Browser: 101.1.38.109
    Chrome: 100.0.4896.127
    Firefox: 99.0.1
    Safari: 14.1.2
  npmPackages:
    @sveltejs/adapter-netlify: next => 1.0.0-next.56
    @sveltejs/adapter-vercel: next => 1.0.0-next.50
    @sveltejs/kit: 1.0.0-next.216 => 1.0.0-next.324
    svelte: ^3.42.1 => 3.47.0

Severity

blocking an upgrade

@bluwy bluwy added the vite label May 2, 2022
@bluwy
Copy link
Member

bluwy commented May 2, 2022

According to the logs, it's failing on the SSR build phase so it's likely a Vite issue, or specifically vitejs/vite#2433. It's great that you have a repro up (though sveltekit specific), as no one really provided one in that issue. I'll close this in favor of the issue, thanks for the report!

@Axeldeblen

This comment was marked as off-topic.

@Axeldeblen

This comment was marked as off-topic.

@itswadesh
Copy link

Changing the max_old_space_size to 16GB at build command fixed the issue

"build": "NODE_OPTIONS=--max_old_space_size=16384 svelte-kit build"

@Axeldeblen

This comment was marked as off-topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants