Ionic, 200+ pages, build production .out of memory error


#1
> ionic cordova build android --prod
> Running app-scripts build: --prod --iscordovaserve --externalIpRequired --nobrowser

> [11:18:38] build prod started ...
> [11:18:38] clean started ...
> [11:18:38] clean finished in 16 ms
> [11:18:38] copy started ...
> [11:18:38] ngc started ...
> [11:19:08] ngc finished in 29.48 s
> [11:19:08] preprocess started ...
> [11:19:08] deeplinks started ...
> [11:19:13] deeplinks finished in 5.05 s
> [11:19:13] optimization started ...
> [11:19:14] copy finished in 35.31 s
> [11:20:06] optimization finished in 52.67 s
> [11:20:06] preprocess finished in 57.72 s
> [11:20:06] webpack started ...

> <--- Last few GCs --->

> 136909 ms: Mark-sweep 1276.6 (1419.2) -> 1276.6 (1435.2) MB, 1325.5 / 0.0 ms [allocation failure] [GC in old space requested].
> 138234 ms: Mark-sweep 1276.6 (1435.2) -> 1276.6 (1435.2) MB, 1324.5 / 0.0 ms [allocation failure] [GC in old space requested].
> 139618 ms: Mark-sweep 1276.6 (1435.2) -> 1284.2 (1419.2) MB, 1383.9 / 0.0 ms [last resort gc].
> 141012 ms: Mark-sweep 1284.2 (1419.2) -> 1291.8 (1419.2) MB, 1393.2 / 0.0 ms [last resort gc].

> <--- JS stacktrace --->

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

> Security context: 0000027F272CFB49 
> 2: /* anonymous */ [D:\ionic2\mytest\node_modules\_enhanced-resolve@3.1.0@enhanced-resolve\lib\ConcordModulesPlugin.js:~19] [pc=000003173103F352] (this=0000010F6398FD69 ,request=000001D2A03FD949 ,callback=0000004F5DBF8B81 )
> 3: applyPluginsParallelBailResult1 [D...

> FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

**I have tried add --max-old-space-size**
**#!/usr/bin/env node --max-old-space-size=4096 ,same as up**
**and i alse modify package.json**

**system info is:**
> global packages:

> @ionic/cli-utils : 1.0.0
> Cordova CLI      : 6.5.0
> Ionic CLI        : 3.0.0
> local packages:

> @ionic/app-scripts              : 1.3.7
> @ionic/cli-plugin-cordova       : 1.0.0
> @ionic/cli-plugin-ionic-angular : 1.0.0
> Ionic Framework                 : ionic-angular 3.2.0
> System:

> Node       : v6.10.3
> OS         : Windows 10
> Xcode      : not installed
> ios-deploy : not installed
> ios-sim    : not installed

#2

no body has this error anymore?

when i use ionic cordova build android ,everything is ok ,
when i use ionic serve also ok.
but when i user ionic cordova build android --prod, out of memory error …


#3

--prod tells the script to do other things, that’s why it is breaking only then.


#4

How do I need to solve this problem? use lazy load or some thing what?

it’s build ok when i remove several pages !!!


#5

When the project is too large(may be 200+ pages), many people will encounter this problem…who can help me?


#6

You have to a) give node more memory or b) make the process use less memory.

--max_old_space_size=4096 is a runtime command, that only is applied on this run. You have to apply this on the build command (Did you do this? How are you building?) or make it permanent somehow.


#7

Thanks for your reply, can you tell me how to add this parameter? or how to make it permanent somehow?

now i only user the follow build command:

ionic cordova build android --prod

how can i add > --max_old_space_size=4096 parameter?

i’m so sorry to you!!!

b) make the process use less memory.
How to do it


#8

I would try:

ionic cordova build android --prod --max_old_space_size=4096

And see if the error message changes. But that’s just me trying naively to fix the problem - I have no idea.


#9

OK,I try like this
ionic cordova build android --prod --max_old_space_size=4096
the errors as:

Running app-scripts build: --prod --iscordovaserve --externalIpRequired --nobrowser

[16:33:57] build prod started …
[16:33:59] clean started …
[16:33:59] clean finished in 4 ms
[16:33:59] copy started …
[16:33:59] ngc started …
[16:34:49] ngc finished in 49.91 s
[16:34:49] preprocess started …
[16:34:49] deeplinks started …
[16:34:56] deeplinks finished in 6.40 s
[16:34:56] optimization started …
[16:34:57] copy finished in 57.88 s
[16:36:12] optimization finished in 76.21 s
[16:36:12] preprocess finished in 82.62 s
[16:36:12] webpack started …

<— Last few GCs —>

209703 ms: Mark-sweep 1254.8 (1438.4) -> 1254.8 (1438.4) MB, 1870.7 / 0.0 ms [allocation failure] [GC in old space requested].
211573 ms: Mark-sweep 1254.8 (1438.4) -> 1254.8 (1438.4) MB, 1869.2 / 0.0 ms [allocation failure] [GC in old space requested].
213658 ms: Mark-sweep 1254.8 (1438.4) -> 1261.5 (1422.4) MB, 2084.9 / 0.0 ms [last resort gc].
215697 ms: Mark-sweep 1261.5 (1422.4) -> 1268.4 (1422.4) MB, 2038.9 / 0.0 ms [last resort gc].

<— JS stacktrace —>

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

Security context: 000001980FECFB49
1: DoRegExpExec [native regexp.js:~87] [pc=000000CD8BD9DF86] (this=000003054F68A181 ,C=000002085088EF11 ,D=000001ED29AC0149 <String[111]: F:\ionic2\iCarApp201705081419_v3\node_modules_ionic-angular@3.2.0@ionic-angular\components\button\button.js.js>,E=0)
2: [Symbol.split] [native regexp.js:~298] [pc=000000CD8C95C93C] (this=000002085088EF11 ,D=0…

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory


#10

Hi sky_zt,

How much RAM do you have in your computer?


#11


#12

I am having the exact same issue. I do have 4gb RAM. I thought this was because of my low RAM.


#13

from my Task Manager,when node.js user memory up to 14xx mb,the process then done,and JavaScript heap out of memory occur。


#14

So this didn’t really change a thing.

You should research how to configure node to use more RAM (or find a way for the process to use less).


#15

can you give same Suggests,i tried the follow,but no effect

1.modify the package.json scripts

“build”: “node --max_old_space_size=4096 ./node_modules/.bin/ionic-app-scripts build”,
“ionic:build”: “node --max_old_space_size=4096 ./node_modules/.bin/ionic-app-scripts build”,

2.modify node_nodules.bin\ionic-app_scripts

#!/bin/sh
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")

case `uname` in
    *CYGWIN*) basedir=`cygpath -w "$basedir"`;;
esac

if [ -x "$basedir/node" ]; then
  "$basedir/node --max_old_space_size=4096"  "$basedir/../_@ionic_app-scripts@1.3.7@@ionic/app-scripts/bin/ionic-app-scripts.js" "$@"
  ret=$?
else 
  node --max_old_space_size=4096  "$basedir/../_@ionic_app-scripts@1.3.7@@ionic/app-scripts/bin/ionic-app-scripts.js" "$@"
  ret=$?
fi
exit $ret

#16

Undo your code and Try this once:

File: project\node_modules\@ionic\app-scripts\bin\ionic-app-scripts.js
Add code just below the #!/usr/bin/env node:

#!/usr/bin/env node --max_old_space_size=4096


#17

thx…i tried it last day ,but can’t success,can you give me your code Screenshot about this ?


#18

I am also stuck at this point because of my RAM. I will just add 4gb RAM more to my computer and will set 4gb memory to Node only. Then i will try again.


#19

can you give me a screenshot of ionic-app-scripts.js code?
i modify like follow ,but when memory use 14XX mb,it out of memory,it’s does not work for me…


#20