Ionic-app-scripts: watch gives `process out of memory` error

Created on 4 Oct 2016  路  9Comments  路  Source: ionic-team/ionic-app-scripts

Note: for support questions, please use one of these channels:

https://forum.ionicframework.com/
http://ionicworldwide.herokuapp.com/

Short description of the problem:

JS changed:   www/build/main.js
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

<--- Last few GCs --->
  604323 ms: Scavenge 1400.5 (1456.9) -> 1400.5 (1456.9) MB, 6.9 / 0 ms (+ 3.6 ms in 1 steps since last GC) [allocation failure] [incremental marking delaying mark-sweep].
  606106 ms: Mark-sweep 1400.5 (1456.9) -> 1398.3 (1456.9) MB, 1782.8 / 0 ms (+ 5.4 ms in 2 steps since start of marking, biggest step 3.6 ms) [last resort gc].
  607878 ms: Mark-sweep 1398.3 (1456.9) -> 1400.0 (1456.9) MB, 1771.3 / 0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x2819473e3ac1 <JS Object>
    1: decode(aka decode) [/.../node_modules/rollup/dist/rollup.js:~304] [pc=0x33141adb6d4b] (this=0x281947304189 <undefined>,mappings=0x817e9d04101 <Very long string[3267509]>)
    2: render [/.../node_modules/rollup/dist/rollup.js:8938] [pc=0x33141b819562] (this=0x25d6fdc32541 <a Bundle with map 0x40b2a259089>,options=0x25d6fdc95a11 <an Obje...

What behavior are you expecting?

npm run build --dev works fine.

Steps to reproduce:

  1. change html in template file and watch kicks into action until it runs out of memory
  2. npm run build --dev to build successfully
    3.
insert any relevant code between the above and below backticks

Which @ionic/app-scripts version are you using?

Your system information:

Cordova CLI: 6.3.1
Ionic Framework Version: 2.0.0-rc.0
Ionic CLI Version: 2.1.0
Ionic App Lib Version: 2.1.0-beta.1
ios-deploy version: 1.8.6
ios-sim version: 5.0.8
OS: Mac OS X El Capitan
Node Version: v5.12.0
Xcode version: Xcode 7.3 Build version 7D175

Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)

Most helpful comment

Still having the same problem with ionic-app-scripts 0.0.28.

All I'm doing is starting ionic serve on a project generated with ionic start, and editing files as normal. After about 10 rebuilds I get

[15:12:51]  bundle dev update started ...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

<--- Last few GCs --->
  221314 ms: Mark-sweep 1393.9 (1457.9) -> 1391.6 (1457.9) MB, 1260.7 / 0 ms [allocation failure] [GC in old space requested].
  222518 ms: Mark-sweep 1391.6 (1457.9) -> 1393.2 (1457.9) MB, 1204.2 / 0 ms [allocation failure] [GC in old space requested].
  223816 ms: Mark-sweep 1393.2 (1457.9) -> 1391.6 (1457.9) MB, 1297.9 / 0 ms [last resort gc].
  225014 ms: Mark-sweep 1391.6 (1457.9) -> 1393.2 (1457.9) MB, 1198.7 / 0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x21467cdb4629 <JS Object>
    2: /* anonymous */(aka /* anonymous */) [***/node_modules/rollup/dist/rollup.js:8375] [pc=0x246fc0e1546a] (this=0x21467cd041b9 <undefined>,segment=0x35ff97ec56a9 <JS Array[4]>)
    3: arguments adaptor frame: 3->1
    4: InnerArrayForEach(aka InnerArrayForEach) [native array.js:~924] [pc=0x246fc0ea389f] (this=0x21467cd041b9 <undefined>,bk=0x11b8e10aae2...

More details:

$ ionic info

Your system information:

Cordova CLI: 6.3.1
Ionic Framework Version: 2.0.0-rc.0
Ionic CLI Version: 2.1.0
Ionic App Lib Version: 2.1.0-beta.1
ios-deploy version: 1.9.0
ios-sim version: 5.0.8
OS: Mac OS X El Capitan
Node Version: v4.6.0
Xcode version: Xcode 8.0 Build version 8A218a

$ npm -v
3.10.8

All 9 comments

Still having the same problem with ionic-app-scripts 0.0.28.

All I'm doing is starting ionic serve on a project generated with ionic start, and editing files as normal. After about 10 rebuilds I get

[15:12:51]  bundle dev update started ...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory

<--- Last few GCs --->
  221314 ms: Mark-sweep 1393.9 (1457.9) -> 1391.6 (1457.9) MB, 1260.7 / 0 ms [allocation failure] [GC in old space requested].
  222518 ms: Mark-sweep 1391.6 (1457.9) -> 1393.2 (1457.9) MB, 1204.2 / 0 ms [allocation failure] [GC in old space requested].
  223816 ms: Mark-sweep 1393.2 (1457.9) -> 1391.6 (1457.9) MB, 1297.9 / 0 ms [last resort gc].
  225014 ms: Mark-sweep 1391.6 (1457.9) -> 1393.2 (1457.9) MB, 1198.7 / 0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x21467cdb4629 <JS Object>
    2: /* anonymous */(aka /* anonymous */) [***/node_modules/rollup/dist/rollup.js:8375] [pc=0x246fc0e1546a] (this=0x21467cd041b9 <undefined>,segment=0x35ff97ec56a9 <JS Array[4]>)
    3: arguments adaptor frame: 3->1
    4: InnerArrayForEach(aka InnerArrayForEach) [native array.js:~924] [pc=0x246fc0ea389f] (this=0x21467cd041b9 <undefined>,bk=0x11b8e10aae2...

More details:

$ ionic info

Your system information:

Cordova CLI: 6.3.1
Ionic Framework Version: 2.0.0-rc.0
Ionic CLI Version: 2.1.0
Ionic App Lib Version: 2.1.0-beta.1
ios-deploy version: 1.9.0
ios-sim version: 5.0.8
OS: Mac OS X El Capitan
Node Version: v4.6.0
Xcode version: Xcode 8.0 Build version 8A218a

$ npm -v
3.10.8

Same with Node v6.7.0, just with a slightly different stack trace:

Security context: 0x606f9fcfb51 <JS Object>
    1: /* anonymous */(aka /* anonymous */) [***/node_modules/rollup/dist/rollup.js:~8365] [pc=0x1913ea7d8dc3] (this=0x606f9f04381 <undefined>,line=0x2cbcdd879d21 <JS Array[6]>)
    2: arguments adaptor frame: 3->1
    3: map [native array.js:~994] [pc=0x1913ea1c1bf2] (this=0x8d5384202f9 <JS Array[78684]>,bq=0x209a9bc88e41 <JS Function (SharedFunctionInfo 0...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/Users/mirko/.nvm/versions/node/v6.7.0/bin/node]
 2:
node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/Users/mirko/.nvm/versions/node/v6.7.0/bin/node]

 3:
v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/Users/mirko/.nvm/versions/node/v6.7.0/bin/node]
 4:
v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/Users/mirko/.nvm/versions/node/v6.7.0/bin/node]
 5:
v8::internal::Runtime_AllocateInTargetSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/Users/mirko/.nvm/versions/node/v6.7.0/bin/node]
 6: 0x1913e92079a7

Again all I'm doing is editing an html template adding a removing a space about 10 times before it runs out of memory.

Logging heapUsed/heapTotal from process.memoryUsage():

[18:53:55]  build dev finished in 11.11s 454M/513M
[18:54:12]  bundle dev update finished in 4.67s 865M/920M
[18:54:19]  bundle dev update finished in 4.44s 675M/734M
[18:54:28]  bundle dev update finished in 5.31s 708M/799M
[18:54:36]  bundle dev update finished in 4.97s 786M/987M
[18:54:43]  bundle dev update finished in 5.05s 884M/1063M
[18:54:52]  bundle dev update finished in 5.32s 975M/1158M
[18:54:59]  bundle dev update finished in 5.17s 1068M/1211M
[18:55:08]  bundle dev update finished in 5.38s 1177M/1318M
[18:55:20]  bundle dev update finished in 6.30s 1242M/1422M
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

The memory leak seems related to the bundleCache. Commenting out that line fixes the out of memory for me, even though the build is a bit slower now.

By the way, this article is pretty interesting: Understanding Garbage Collection and hunting Memory Leaks in Node.js.

I hope there will be some sort of solution soon, It is really annoying since it slows down development/loading significantly compared to beta 11. Does it have to do with the way rollup is bundling in General ? Because up to now there is not a fix, and most have this problem.

I think the bundleCache global in bundle.ts is not freed because it's captured by the clearCachedModule function. I would suggest removing that function altogether (works for me) but I'm not entirely clear what runTemplateUpdate is doing so I'll stop my investigation here.

Hello! Thanks for all the info! I am going to close this issue as a duplicate of https://github.com/driftyco/ionic-app-scripts/issues/64. Thanks!

I've was able to workaround this issue on Ionic v3.5, Ionic cli 3.4.0, and Node.js 6.9.1. We have a big app with lots of modules and heap space errors occurring every build, whether "ionic serve", or "ionic cordova run --prod".

Modify your ionic.cmd file in C:\Users\\AppData\Roaming\npm by adding --max_old_space_size. I set mine to 8096.

@IF EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" --max_old_space_size=8048 "%~dp0\node_modules\ionic\bin\ionic" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node --max_old_space_size=8048 "%~dp0\node_modules\ionic\bin\ionic" %*
)

Good luck!

@jgw96 Everywhere you closed this issue! Have you found any solution for this (FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory) error?

Was this page helpful?
0 / 5 - 0 ratings