Ionic-cli: Allocation failed - JavaScript heap out of memory

Created on 2 Oct 2016  路  23Comments  路  Source: ionic-team/ionic-cli

Ionic Serve runs without problems, but Ionic run iOS gives me this:
I already updated to app-scripts 0.0.27 to get
https://github.com/driftyco/ionic-app-scripts/pull/44

[16:22:46] bundle prod started ...
<--- Last few GCs --->
167123 ms: Mark-sweep 1308.5 (1434.1) -> 1308.5 (1434.1) MB, 1012.0 / 0.0 ms [allocation failure] [GC in old space requested].
168098 ms: Mark-sweep 1308.5 (1434.1) -> 1308.5 (1434.1) MB, 975.3 / 0.0 ms [allocation failure] [GC in old space requested].
169101 ms: Mark-sweep 1308.5 (1434.1) -> 1318.0 (1418.1) MB, 1002.5 / 0.0 ms [last resort gc].
170079 ms: Mark-sweep 1318.0 (1418.1) -> 1327.5 (1418.1) MB, 977.2 / 0.0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x1de7fe7cfb51
1: decode(aka decode) [/Users/Jan/Documents/Wohntraum360/wohntraumapp_v2/wohntraumapp/node_modules/rollup/dist/rollup.js:~304] [pc=0x890dfd2cecf](this=0x1de7fe704381 ,mappings=0x2036de204201 2: render [/Users/Jan/Documents/Wohntraum360/wohntraumapp_v2/wohntraumapp/node_modules/rollup/dist/rollup.js:8938] [pc=0x890e04420e6] (this=0x63e3a0f75d1 FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1:
node::Abort() [/usr/local/bin/node]
2:
node::FatalException(v8::Isolate*, v8::Local, v8::Localv8::Message) [/usr/local/bin/node]
3:
v8::internal::V8::FatalProcessOutOfMemory(char const_, bool)
[/usr/local/bin/node]
4:
v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/usr/local/bin/node]
5:
v8::internal::Runtime_AllocateInTargetSpace(int, v8::internal::Object__, v8::internal::Isolate_) [/usr/local/bin/node]
6:
0x890dfc079a7
Caught exception:
undefined

Most helpful comment

Still occurs in:
ionic/app-scripts": "3.1.9",
Ionic CLI Version: "3.20.0"

All 23 comments

I've gotten this too while using ionic serve. Specifically while making changes really quick to the codebase as I was migrating to RC0. Maybe saving files too quickly?

Related to #1433 ?

@tlaverdure ionic serves performs well on the first try. But yes, if i change files quickly this runs into error too. But here the ionic run/ionic build query doesn't work at all. It always crashes at the bundle step... I tried the stock tab app, this works fine...

@Lingomat Maybe...

I changed following line in package.json:

"build": "ionic-app-scripts watch",
into
"build": "node --max-old-space-size=2048 ./node_modules/.bin/ionic-app-scripts build",

now it works!

@chack That will work for now, but we are aware of this issue still occuring and are working on a fix.

Can I get a more detailed capture (more lines of output) of your command lines before the failure. This should help in troubleshooting.

Thanks!

@jthoms1 not to mention this heap out of memory is happening way too often but the whole build it's also way too slow...

Anyway, i'm getting this after some changes .. here are my lines of output in ionic serve command:

[23:29:03]  typescript compilation started ...
[23:29:07]  typescript compilation finished in 4.49 s
[23:29:08]  bundle dev update started ...
<--- Last few GCs --->
 2988548 ms: Mark-sweep 1263.5 (1434.9) -> 1263.5 (1434.9) MB, 1506.5 / 0 ms [allocation failure] [GC in old space requested].
 2990112 ms: Mark-sweep 1263.5 (1434.9) -> 1263.5 (1434.9) MB, 1564.3 / 0 ms [allocation failure] [GC in old space requested].
 2991814 ms: Mark-sweep 1263.5 (1434.9) -> 1263.5 (1434.9) MB, 1702.2 / 0 ms [last resort gc].
 2993408 ms: Mark-sweep 1263.5 (1434.9) -> 1263.5 (1434.9) MB, 1593.6 / 0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x2c4c367c9e31 <JS Object>
    1: decode(aka decode) [/Users/viegas/Faculdade/4/TIDIR/APP/Client/node_modules/rollup/dist/rollup.js:~304] [pc=0x252310ec20e3] (this=0x2c4c36704189 <undefined>,mappings=0x2bab73904101 <Very long string[3183545]>)
    2: render [/Users/viegas/Faculdade/4/TIDIR/APP/Client/node_modules/rollup/dist/rollup.js:8938] [pc=0x252314bf4a66] (this=0x2dad12fe859 <a Bundle with map 0x20dc57458691>,option...
FATAL ERROR: CALL_AND_RETRY_LAST 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::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/usr/local/bin/node]
 5:
v8::internal::Runtime_AllocateInTargetSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]

 6: 0x25230e106338
 7: 0x252310ec20e3

Experiencing the same:

[11:41:40]  bundle dev update started ...
<--- Last few GCs --->
 3659362 ms: Mark-sweep 1272.3 (1434.8) -> 1264.9 (1434.8) MB, 1212.9 / 0.0 ms [allocation failure] [GC in old space requested].
 3660595 ms: Mark-sweep 1264.9 (1434.8) -> 1264.9 (1434.8) MB, 1233.5 / 0.0 ms [allocation failure] [GC in old space requested].
 3661845 ms: Mark-sweep 1264.9 (1434.8) -> 1271.6 (1411.8) MB, 1249.0 / 0.0 ms [last resort gc].
 3663106 ms: Mark-sweep 1271.6 (1411.8) -> 1279.7 (1411.8) MB, 1261.2 / 0.0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x1ccce25cfb51 <JS Object>
        1: /* anonymous */(aka /* anonymous */) [/Users/rico/smartcode/projects/foo/app/node_modules/rollup/dist/rollup.js:~8368] [pc=0x3d8448f34906] (this=0x1ccce2504381 <undefined>,segment=0x112b16b92c89 <JS Array[4]>)
        2: arguments adaptor frame: 3->1
        3: InnerArrayForEach(aka InnerArrayForEach) [native array.js:~935] [pc=0x3d8448efc872] (this=0x1ccce2504381 <undefined>,bq=0x3643...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: 
node::Abort() [/usr/local/Cellar/node/6.7.0/bin/node]
 2: 
node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/Cellar/node/6.7.0/bin/node]
 3: 
v8::Utils::ReportApiFailure(char const*, char const*) [/usr/local/Cellar/node/6.7.0/bin/node]
 4: 
v8::Utils::ApiCheck(bool, char const*, char const*) [/usr/local/Cellar/node/6.7.0/bin/node]
 5: 
v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/Cellar/node/6.7.0/bin/node]
 6: 
v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/usr/local/Cellar/node/6.7.0/bin/node]
 7: 
v8::internal::Runtime_AllocateInTargetSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/Cellar/node/6.7.0/bin/node]
 8: 
0x3d8444e079a7
 9: 0x3d8448f34906

Using ionic/[email protected].

Hello all! I am going to close this issue for now as it has been fixed in ionic-app-scripts v0.0.30. To update your project to the latest version of ionic-app-scriptsjust runnpm install` inside your project. Thanks!

Hello!
I'm having this issue

> com.brandbassador@ ionic:build /Users/arturalkaim/brandbassador/brandbassador-ionic-rc
> ionic-app-scripts build "--release" "--prod"

[19:05:05]  ionic-app-scripts 1.1.4 
[19:05:05]  build prod started ... 
[19:05:05]  clean started ... 
[19:05:05]  clean finished in 1 ms 
[19:05:05]  copy started ... 
[19:05:05]  ngc started ... 
[19:05:32]  ngc finished in 26.56 s 
[19:05:32]  preprocess started ... 
[19:05:32]  optimization started ... 
[19:05:50]  copy finished in 44.52 s 
[19:05:52]  optimization finished in 20.52 s 
[19:05:52]  preprocess finished in 20.52 s 
[19:05:52]  webpack started ... 
[19:08:35]  webpack finished in 163.22 s 
[19:08:35]  sass started ... 
[19:08:36]  transpile bundle started ... 
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: 
<--- Last few GCs --->

  246245 ms: Mark-sweep 1331.0 (1434.9) -> 1317.6 (1434.9) MB, 1059.5 / 0.0 ms [allocation failure] [GC in old space requested].
  247320 ms: Mark-sweep 1317.6 (1434.9) -> 1317.6 (1434.9) MB, 1074.6 / 0.0 ms [allocation failure] [GC in old space requested].
  248394 ms: Mark-sweep 1317.6 (1434.9) -> 1323.1 (1406.9) MB, 1073.4 / 0.0 ms [last resort gc].
  249472 ms: Mark-sweep 1323.1 (1406.9) -> 1328.5 (1406.9) MB, 1077.6 / 0.0 ms [last resort gc].


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0x390ea2fcfb51 <JS Object>
    2: encodeLastRecordedSourceMapSpan [/Users/arturalkaim/brandbassador/brandbassador-ionic-rc/node_modules/typescript/lib/typescript.js:~35513] [pc=0x1142fc57361a] (this=0x390ea2fe6f21 <JS Global Object>)
    3: emitPos [/Users/arturalkaim/brandbassador/brandbassador-ionic-rc/node_modules/typescript/lib/typescript.js:~35549] [pc=0x1142fc56075d] (this=0x390ea2fe6f21 <JS Global Object>,pos=1429...

node::Abort() [/Users/arturalkaim/.nvm/versions/node/v6.9.1/bin/node]
 2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/Users/arturalkaim/.nvm/versions/node/v6.9.1/bin/node]
 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/Users/arturalkaim/.nvm/versions/node/v6.9.1/bin/node]
 4: v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationSpace) [/Users/arturalkaim/.nvm/versions/node/v6.9.1/bin/node]
 5: v8::internal::Runtime_AllocateInTargetSpace(int, v8::internal::Object**, v8::internal::Isolate*) [/Users/arturalkaim/.nvm/versions/node/v6.9.1/bin/node]
 6: 0x1142fa8079a7
 7: 0x1142fae3bdcd
 8: 0x1142fc57361a
 9: 0x1142fc56075d

Any help?

Thanks
ionic info output:

Your system information:

Cordova CLI: 6.4.0 
Ionic Framework Version: 2.1.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.1.4
ios-deploy version: 1.9.0 
ios-sim version: Not installed
OS: macOS Sierra
Node Version: v6.9.1
Xcode version: Xcode 8.2.1 Build version 8C1002

@arturalkaim I upgraded typescript to 2.0.10 and it worked for me.

Same problem..

    Cordova CLI: 6.3.1 
    Ionic Framework Version: 2.2.0
    Ionic CLI Version: 3.0.0-beta.4
    ios-deploy version: 1.9.1 
    ios-sim version: 5.0.13 
    OS: OS X El Capitan
    Node Version: v6.9.1
    Xcode version: Xcode 8.2 Build version 8C38

(typescript 2.0.9)
webpack finish in 247 s !
Upgrading to typescript 2.0.10 doesn't resolve the problem. (Even the last version 2.2.1)

@tamerbak I was running into the same issue, the only thing that I could work around this issue was to edit top of the file ./node_modules/lib/@ionic/app-scripts/bin/ionic-app-scripts.js and add the following to the top of the file:
#!/usr/bin/env node --max-old-space-size=4096

@drewhawken, Thanks for this workaround, this is what I did finally.. But I had to downgrade ionic CLI version to 2.2.1 to overcome this issue.
I should notify that, I'm working on another application with less pages, and this issue doesn't appear, with the last beta version of ionic CLI and without your workaround.

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:UsersAppDataRoamingnpm by adding --max_old_space_size. I set mine to 8096.

@IF EXIST "%~dp0node.exe" (
"%~dp0node.exe" --max_old_space_size=8048 "%~dp0node_modulesionicbinionic" %*
) ELSE (
@SETLOCAL
@SET PATHEXT=%PATHEXT:;.JS;=;%
node --max_old_space_size=8048 "%~dp0node_modulesionicbinionic" %*
)

Good luck!

@timothybclayton Thanks for posting your solution! This modification in ionic.cmd worked for me.

ran into same issue, here's my info

cli packages: (/Users/qiluo/Dev/ionic-apps/fpp-mom-app/node_modules)

    @ionic/cli-plugin-proxy : 1.4.0
    @ionic/cli-utils        : 1.7.0
    ionic (Ionic CLI)       : 3.7.0

global packages:

    Cordova CLI : 7.0.1

local packages:

    @ionic/app-scripts              : 2.1.3
    @ionic/cli-plugin-cordova       : 1.4.1
    @ionic/cli-plugin-ionic-angular : 1.3.2
    Cordova Platforms               : android 6.2.3 ios 4.4.0
    Ionic Framework                 : ionic-angular 3.6.0

System:

    Android SDK Tools : 25.2.5
    Node              : v6.11.0
    OS                : macOS Sierra
    Xcode             : Xcode 8.3.3 Build version 8E3004b
    ios-deploy        : 1.9.1
    ios-sim           : 5.0.13
    npm               : 3.10.10

How to workaround it on OSX? Thanks

@qiluo if you take a look at my previous comment, I had to reimplement it for this build of the tool.

Adding the following to ./node_modules/lib//bin/ionic-app-scripts.js:
#!/usr/bin/env node --max-old-space-size=4096

@drewhawken, thanks, I've tried your solution which properly worked-around the issue. But the issue occurred on our build machine (one Mac mini), the build dir got wiped every time and I need a global permanent configuration, for the moment I found this tiny tool can do the trick, I added it to our pre-build hook.

Anyway, hopefully there will be a cli option since ionic itself will get upgraded sometimes, the environment would change as well sometimes.

If on macOS or linux, this might work (untested):

put this in .bashrc and open a new terminal:

alias ionic="node --max-old-space-size=4096 $(which ionic)"

Still occurs in ionic/app-scripts": "3.1.8

Still occurs in:
ionic/app-scripts": "3.1.9",
Ionic CLI Version: "3.20.0"

Still occurs in:
ionic/app-scripts": "3.1.9",
Ionic CLI Version: "3.20.0"

Still occurs in:
ionic/app-scripts": "3.1.10"

Was this page helpful?
0 / 5 - 0 ratings