question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ionic build prod very slow and eventually fails with Javascript heap out of memory

See original GitHub issue

Bug 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:closed
  • Created 5 years ago
  • Reactions:1
  • Comments:21 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
ChargerIICcommented, Jun 14, 2018

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:

  1. Use Ionic-Run-Scripts to manage the build (same problem)
  2. Update NPM to latest
  3. Use NPM Build instead of Ionic Build

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:

cli packages: (C:\Users\vburt\AppData\Roaming\npm\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.10
    Cordova Platforms  : browser 5.0.3
    Ionic Framework    : ionic-angular 3.9.2

System:
    Node : v8.11.1
    npm  : 6.1.0
    OS   : Windows 10

Environment Variables:
    ANDROID_HOME : not set

Misc:
    backend : pro
0reactions
ionitron-bot[bot]commented, Oct 18, 2018

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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

ionic build prod very slow and eventually fails with Javascript ...
Hi there! This is a long outstanding issue in ionic-app-scripts, not the framework it self. This is due to low memory limits in...
Read more >
How to solve JavaScript heap out of memory in angular or ...
Cause of JavaScript heap out of memory error​​ Ionic 3 is based on angular, and it uses ng , which in itself uses...
Read more >
angular - JavaScript heap out of memory Ionic 3 prod build
This happens when your application consumes more memory than default allocated one. There are two things that you can do.
Read more >
JavaScript heap out of memory ionic 3 Build prod Issue
Hello, Currently I am trying to build my ionic project to android apk file but I ran into CALL_AND_RETRY_LAST Allocation failed - JavaScript...
Read more >
4 Types of Memory Leaks in JavaScript and How to Get Rid Of ...
Learn about memory leaks in JavaScript and what can be done to solve ... Memory leaks are a problem every developer has to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found