marvin ralph
marvin ralph

Reputation: 1280

Ionic 3 JavaScript heap out of memory

I'm working on an ionic android app which is quiet huge. When i run ionic build --prod i get the ff error:

--- Last few GCs --->

[4220:000002B5705AEDC0]   185812 ms: Mark-sweep 1382.2 (1425.5) -> 1381.6 (1424.5) MB, 1157.1 / 0.0 ms  (average mu = 0.092, current mu = 0.040) allocation failure scavenge might not succeed
[4220:000002B5705AEDC0]   185823 ms: Scavenge 1382.4 (1424.5) -> 1381.8 (1425.0) MB, 6.1 / 0.0 ms  (average mu = 0.092, current mu = 0.040) allocation failure
[4220:000002B5705AEDC0]   185831 ms: Scavenge 1382.6 (1425.0) -> 1382.0 (1425.5) MB, 4.2 / 0.0 ms  (average mu = 0.092, current mu = 0.040) allocation failure


<--- JS stacktrace --->

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

    0: ExitFrame [pc: 000002EC1505C5C1]
Security context: 0x00f46dd9e6e1 <JSObject>
    1: symbolToName(aka symbolToName) [00000239DECFEC99] [C:\Users\Juls\Desktop\Chapel\node_modules\@angular-devkit\build-optimizer\node_modules\typescript\lib\typescript.js:~26322] [pc=000002EC16294DD8](this=0x027dfb2826f1 <undefined>,symbol=0x001449973021 <SymbolObject map = 0000006B919CC659>,context=0x0251729a2041 <Object map = 0000006B9199D6E9>,meaning...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 00007FF63489ECF5
 2: 00007FF6348781A6
 3: 00007FF634878BB0
 4: 00007FF634B09AAE
 5: 00007FF634B099DF
 6: 00007FF635047724
 7: 00007FF63503DE87
 8: 00007FF63503C3FC
 9: 00007FF635045377
10: 00007FF6350453F6
11: 00007FF634BE84B7
12: 00007FF634C8019A
13: 000002EC1505C5C1
[ERROR] An error occurred while running subprocess ionic-app-scripts.

        ionic-app-scripts build --prod exited with exit code 134.

        Re-running this command with the --verbose flag may provide more information.

I've tried every possible solution on the internet but none of them seem to work. These are a list of things I've tried that didnt resolve my issue:

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

Editing node.cmd to that

running export NODE_OPTIONS=--max_old_space_size=4096 before running ionic build --prod bupped up the size to 8096 and still prints the above error message.

Modify ng.cmd:

@IF EXIST "%~dp0\node.exe" (
  "%~dp0\node.exe" --max_old_space_size=5048 "%~dp0\..\angular-cli\bin\ng" %*
) ELSE (
  @SETLOCAL
  @SET PATHEXT=%PATHEXT:;.JS;=;%
  node --max_old_space_size=5048 "%~dp0\..\angular-cli\bin\ng" %*
)

Modify ngc.cmd :

@IF EXIST "%~dp0\node.exe" (
  "%~dp0\node.exe" --max_old_space_size=5048 "%~dp0\..\@angular\compiler-cli\src\main.js" %*
) ELSE (
  @SETLOCAL
  @SET PATHEXT=%PATHEXT:;.JS;=;%
  node --max_old_space_size=5048 "%~dp0\..\@angular\compiler-cli\src\main.js" %*
)

Below is a list of technical informations that could help find out what to do:

Ionic:

   ionic (Ionic CLI)  : 4.12.0 (C:\Users\Juls\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework    : ionic-angular 3.9.3
   @ionic/app-scripts : 3.2.1

Cordova:

   cordova (Cordova CLI) : 9.0.0
   Cordova Platforms     : android 8.0.0
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.2, (and 21 other plugins)

System:

   Android SDK Tools : 26.1.1 (C:\Users\Juls\AppData\Local\Android\Sdk)
   NodeJS            : v10.14.1 (C:\Program Files\nodejs\node.exe)
   npm               : 6.4.1
   OS                : Windows 10

Upvotes: 0

Views: 1310

Answers (2)

Wime Dumingos
Wime Dumingos

Reputation: 29

Try downgrade your app-script to 3.1.4 it worked for me.

Upvotes: 0

Jay Ordway
Jay Ordway

Reputation: 1749

I have noticed this often when the version of @angular-devkit/build-optimizer is old. I would update this to at least version 0.11.4.

Try npm i @angular-devkit/[email protected] or a newer version

Upvotes: 1

Related Questions