Ionic-cli: Allocation failed - JavaScript heap out of memory (when building via cordova:build)

Created on 16 Mar 2017  路  4Comments  路  Source: ionic-team/ionic-cli

Ionic informations:

Your system information:

    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

package.js :

    "@ionic/app-scripts": "1.1.4",
    "@ionic/cli-build-ionic-angular": "0.0.3",
    "@ionic/cli-plugin-cordova": "0.0.9",
    "typescript": "2.0.10"

Error :

ionic cordova:build ios --release --prod
  Running app-scripts build: --prod --iscordovaserve --nobrowser
[10:31:10]  build prod started ... 
[10:31:10]  clean started ... 
[10:31:10]  clean finished in 5 ms 
[10:31:10]  copy started ... 
[10:31:10]  ngc started ... 
[10:31:56]  ngc finished in 45.49 s 
[10:31:56]  preprocess started ... 
[10:31:56]  optimization started ... 
[10:32:10]  copy finished in 59.45 s 
[10:32:20]  optimization finished in 24.16 s 
[10:32:20]  preprocess finished in 24.16 s 
[10:32:20]  webpack started ... 
[10:36:41]  webpack finished in 260.92 s 
[10:36:41]  sass started ... 
[10:36:41]  transpile bundle started ... 

<--- Last few GCs --->

  368275 ms: Mark-sweep 1316.9 (1434.2) -> 1311.3 (1434.2) MB, 1047.7 / 0.0 ms [allocation failure] [GC in old space requested].
  369353 ms: Mark-sweep 1311.3 (1434.2) -> 1311.3 (1434.2) MB, 1076.9 / 0.0 ms [allocation failure] [GC in old space requested].
  370726 ms: Mark-sweep 1311.3 (1434.2) -> 1316.0 (1404.2) MB, 1372.9 / 0.0 ms [last resort gc].
  372124 ms: Mark-sweep 1316.0 (1404.2) -> 1321.0 (1404.2) MB, 1396.6 / 0.0 ms [last resort gc].


<--- JS stacktrace --->

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

Security context: 0x203b6b8cfb51 <JS Object>
    2: encodeLastRecordedSourceMapSpan [/Users/tim/Documents/migration/node_modules/typescript/lib/typescript.js:~35518] [pc=0x8d57dcd1498] (this=0x203b6b8e6f21 <JS Global Object>)
    3: emitPos [/Users/tim/Documents/migration/node_modules/typescript/lib/typescript.js:~35554] [pc=0x8d57dcc1717] (this=0x203b6b8e6f21 <JS Global Object>,pos=12190170)
    4: emi...

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: 0x8d57a7079a7
Abort trap: 6

Most helpful comment

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!

All 4 comments

This appears to be an issue with @ionic/app-scripts. I am going to move the issue to that repo. Thanks!

This issue was moved to driftyco/ionic-app-scripts#818

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!

thank you @timothybclayton

Was this page helpful?
0 / 5 - 0 ratings