ionic build prod very slow and eventually fails with Javascript heap out of memory
See original GitHub issueBug Report
Ionic Info
cli packages: (/usr/local/lib/node_modules)
@ionic/cli-utils : 1.19.2
ionic (Ionic CLI) : 3.20.0
global packages:
cordova (Cordova CLI) : 8.0.0
local packages:
@ionic/app-scripts : 3.1.8
Cordova Platforms : android 7.0.0 browser 5.0.3
Ionic Framework : ionic-angular 3.9.2
System:
Node : v8.11.2
npm : 5.6.0
OS : macOS High Sierra
Xcode : Xcode 9.3 Build version 9E145
Environment Variables:
ANDROID_HOME : not set
Misc:
backend : pro
Describe the Bug Running “ionic build --prod” runs for about 90 minutes then fails with the following output. This command had been working for me for a few months with total build times around 2-3 minutes. Something changed in the last 2 weeks. I have not changed any project dependencies, but I have added a few pages and providers since then. However I cannot pinpoint what caused this to change so dramatically. My project has 17 pages and 8 providers so not a crazy number of files.
Running app-scripts build: --prod
[12:41:05] build prod started ...
[12:41:05] clean started ...
[12:41:05] clean finished in 4 ms
[12:41:05] copy started ...
[12:41:05] deeplinks started ...
[12:41:05] deeplinks finished in 154 ms
[12:41:05] ngc started ...
[12:41:18] ngc finished in 13.11 s
[12:41:18] preprocess started ...
[12:41:18] preprocess finished in less than 1 ms
[12:41:18] webpack started ...
[12:41:19] copy finished in 13.69 s
<--- Last few GCs --->
ed[52157:0x102801e00] 6458092 ms: Mark-sweep 6726.9 (6882.0) -> 6727.6 (6883.5) MB, 4543.3 / 0.0 ms (+ 983.9 ms in 231 steps since start of marking, biggest step 13.4 ms, walltime since start of marking 5598 ms) allocation failure scavenge might not succe[52157:0x102801e00] 6463423 ms: Mark-sweep 6728.1 (6883.5) -> 6727.4 (6898.0) MB, 5282.8 / 0.0 ms (+ 42.3 ms in 9 steps since start of marking, biggest step 12.6 ms, walltime since start of marking 5328 ms) allocation failure scavenge might not succeed
<--- JS stacktrace --->
Cannot get stack trace in GC.
FATAL ERROR: MarkCompactCollector: semi-space copy, fallback in old gen Allocation failed - JavaScript heap out of memory
1: node::Abort() [/usr/local/bin/node]
2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
4: v8::internal::EvacuateNewSpaceVisitor::AllocateTargetObject(v8::internal::HeapObject*, int, v8::internal::HeapObject**) [/usr/local/bin/node]
5: v8::internal::EvacuateNewSpaceVisitor::Visit(v8::internal::HeapObject*, int) [/usr/local/bin/node]
6: void v8::internal::LiveObjectVisitor::VisitBlackObjectsNoFail<v8::internal::EvacuateNewSpaceVisitor, v8::internal::MajorNonAtomicMarkingState>(v8::internal::MemoryChunk*, v8::internal::MajorNonAtomicMarkingState*, v8::internal::EvacuateNewSpaceVisitor*, v8::internal::LiveObjectVisitor::IterationMode) [/usr/local/bin/node]
7: v8::internal::Evacuator::EvacuatePage(v8::internal::Page*) [/usr/local/bin/node]
8: v8::internal::PageEvacuationTask::RunInParallel() [/usr/local/bin/node]
9: v8::internal::ItemParallelJob::Task::RunInternal() [/usr/local/bin/node]
10: v8::internal::ItemParallelJob::Run() [/usr/local/bin/node]
11: void v8::internal::MarkCompactCollectorBase::CreateAndExecuteEvacuationTasks<v8::internal::FullEvacuator, v8::internal::MarkCompactCollector>(v8::internal::MarkCompactCollector*, v8::internal::ItemParallelJob*, v8::internal::RecordMigratedSlotVisitor*, v8::internal::MigrationObserver*, long) [/usr/local/bin/node]
12: v8::internal::MarkCompactCollector::EvacuatePagesInParallel() [/usr/local/bin/node]
13: v8::internal::MarkCompactCollector::Evacuate() [/usr/local/bin/node]
14: v8::internal::MarkCompactCollector::CollectGarbage() [/usr/local/bin/node]
15: v8::internal::Heap::MarkCompact() [/usr/local/bin/node]
16: v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
17: v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
18: v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/usr/local/bin/node]
19: v8::internal::Runtime_AllocateInNewSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
20: 0x1bdf00f842fd
Abort trap: 6
Steps to Reproduce Run “ionic build --prod” and wait 90 minutes. Unfortunately I am unable to provide my source code.
Related Code N/A
Expected Behavior I expect the production build to finish in a reasonable number of minutes without errors.
Additional Context N/A
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:21 (2 by maintainers)

Top Related StackOverflow Question
Experiencing the same issue on Ionic 3.20/Angular 5.2.10. A quick look through StackOverflow shows that a few people have experienced the problem but no one has found an answer.
I’ve attempted the following resolutions, but the problem still persists:
I’m using (and attempting to build for) the browser environment. If I do a build without ‘–prod’ it suceeds, if I attempt a prod build it’ll hang for up to 6 hours, with Node slowly accumulating more and more memory.
My project can be found here if soemone wants to reproduce: https://github.com/ChargerIIC/HouseOfBurtFront
Ionic Info:
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.