Skip to content
This repository was archived by the owner on May 1, 2020. It is now read-only.

JavaScript heap out of memory !!!!!! #1467

Open
liangwenzhong opened this issue Aug 20, 2018 · 15 comments
Open

JavaScript heap out of memory !!!!!! #1467

liangwenzhong opened this issue Aug 20, 2018 · 15 comments

Comments

@liangwenzhong
Copy link

Short description of the problem:

Ionic:

ionic (Ionic CLI) : 4.1.0 (/usr/local/lib/node_modules/ionic)
Ionic Framework : ionic-angular 2.2.0
@ionic/app-scripts : 3.1.11

Cordova:

cordova (Cordova CLI) : 6.5.0
Cordova Platforms : none
Cordova Plugins : no whitelisted plugins (0 plugins total)

System:

NodeJS : v10.8.0 (/usr/local/Cellar/node/10.8.0/bin/node)
npm : 6.2.0
OS : macOS High Sierra

Environment:

ANDROID_HOME : not set

description:

over 100 pages.

when exec :
ionic-app-scripts build --max_old_space_size=8192 --aot --optimizeJs --minifyjs --minifycss

error:

[12:04:24] ionic-app-scripts 3.1.11
[12:04:24] build dev started ...
[12:04:24] clean started ...
[12:04:24] clean finished in 3 ms
[12:04:24] copy started ...
[12:04:25] copy finished in 287 ms
[12:04:25] deeplinks started ...
[12:04:25] deeplinks finished in 13 ms
[12:04:25] ngc started ...
[12:06:37] ngc finished in 132.50 s
[12:06:37] preprocess started ...
[12:06:37] preprocess finished in less than 1 ms
[12:06:37] webpack started ...

<--- Last few GCs --->

[3274:0x104802a00] 1762980 ms: Mark-sweep 9571.9 (10413.5) -> 9571.3 (10372.5) MB, 662.2 / 0.0 ms (average mu = 0.199, current mu = 0.165) allocation failure GC in old space requested
[3274:0x104802a00] 1763040 ms: Scavenge 9586.3 (10386.8) -> 9585.4 (10386.8) MB, 11.7 / 0.0 ms (average mu = 0.199, current mu = 0.165) allocation failure
[3274:0x104802a00] 1763094 ms: Scavenge 9600.8 (10401.5) -> 9600.0 (10402.0) MB, 12.0 / 0.0 ms (average mu = 0.199, current mu = 0.165) allocation failure

<--- JS stacktrace --->

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

0: ExitFrame [pc: 0x23bb22e041bd]

Security context: 0x2b02501e789
1: DoJoin(aka DoJoin) [0x2b025005ab9] [native array.js:~87] [pc=0x23bb22ee00e3](this=0x2b059f822e1 ,l=0x2b147884811 <JSArray[653]>,m=653,A=0x2b059f82381 ,w=0x2b059fb05f1 <String[1]: >,v=0x2b059f823f1 )
2: Join(aka Join) [0x2b025005b09] [native array.js:~112] [pc=0x23bb22eea014](this=0x2b059f822e1 ,l=0x2b147884811 <J...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 0x100038460 node::Abort() [/usr/local/bin/node]
2: 0x1000385ea node::FatalTryCatch::~FatalTryCatch() [/usr/local/bin/node]
3: 0x1001881eb v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
4: 0x10018818d v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
5: 0x100461052 v8::internal::Heap::UpdateSurvivalStatistics(int) [/usr/local/bin/node]
6: 0x100462cf5 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [/usr/local/bin/node]
7: 0x1004603b7 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
8: 0x10045f308 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
9: 0x100467507 v8::internal::Heap::AllocateRawWithRetry(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [/usr/local/bin/node]
10: 0x100446f64 v8::internal::Factory::NewRawTwoByteString(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
11: 0x100680b41 v8::internal::Runtime_StringBuilderJoin(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
12: 0x23bb22e041bd
13: 0x23bb22ee00e3
14: 0x23bb22eea014
15: 0x23bb2505b7e9
16: 0x23bb24bb31b0
17: 0x23bb2588664f
18: 0x23bb22e0c5a3
19: 0x23bb22efb84c
20: 0x23bb22e13a09

@mydoal
Copy link

mydoal commented Sep 9, 2018

same here. so many complaints about this and still no real solution:

#1422
#1247
#1036
firebase/firebase-js-sdk#904

the only suggestions I came across was to remove --prod and use --aot --uglifyjs --minifyjs --minifycss --release instead which does not have the same effect as --prod as far as loading time of startup is concerned and to downgrade firebase to 4.12.1 which is unacceptable since version 4.13.0 has a critical bug fix.
ionic team, any solutions here?

@killian2301
Copy link

Same here... No solution yet?

@lordgreg
Copy link

1 month into the issue, no solutions.

@basvdijk
Copy link

basvdijk commented Oct 2, 2018

Same issue here, but without using Firebase. It kinda scares me that all of a sudden you are unable to build your large app and have to spend hours figuring out how to build for a new app release. Hope this is being solved soon.

Can confirm --prod triggers the memory error, with --aot --uglifyjs --minifyjs --minifycss --release as suggested by @mydoal gave no memory problems, but a much larger app instead.

@basvdijk
Copy link

basvdijk commented Oct 5, 2018

I've found a solution which was pointed out in an old message on the forum: https://forum.ionicframework.com/t/3-7-0-ios-build-with-prod-not-working/107061/24

Open node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js

Change the first line from:
#!/usr/bin/env node
into
#!/usr/bin/env node --max-old-space-size=4096

I tried values 1024 and 2048, but for my relatively large app I needed 4096.

Now I am able to run ionic cordova build android --prod --release with out the FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory error.

Posted this solution in #1467, #1036 and #1247

@kirillgroshkov
Copy link

Found a better solution, to specify NODE env variable before the build: export NODE_OPTIONS=--max-old-space-size=4096

Credits to: https://stackoverflow.com/a/48895989/4919972

@basvdijk
Copy link

basvdijk commented Nov 2, 2018

@kirillgroshkov Nice find! For future readers, take the warning from the stackoverflow comments into account when applying the export NODE_OPTIONS:

Word of warning: do not set this as an environment variable on your Windows machine. It breaks everything. It broke GitKraken, Slack, the VS2017 installer (which is chromium-based), Azure-related VS2017 extensions, and even the "Extensions and Updates" menu item in VS2017.

@lellisls
Copy link

I'm facing the same issue here, and the build fails even after using the "max-old-space-size" option.
I wish I could have another way to check what is happening in this webpack step that is taking so much memory. But even with the verbose mode turned on, I cannot have any additional information about the webpack step.
I don't want to disable the production flag. There should be another way to fix this issue.

@adil-Pathan
Copy link

Set NODE_OPTIONS environment variable with value as --max-old-space-size=4096 in windows os to solve this issue.

@JNSantiago
Copy link

JNSantiago commented Dec 3, 2018

did not work for me

@JNSantiago
Copy link

only add "@firebase/database": "0.2.1", for your package.json, and works.

@jayordway
Copy link

I have seen these errors happen frequently throughout the different Ionic 4 beta releases. Typically I install a more up to date version of the @angular-devkit/build-optimizer. As I write this, we are on 0.11.4 as being the newest version. When I updated this I had to update the webpack.config.js to remove the purify plugin per angular/angular-cli#11370

After this I was able to do a prod build once again, so far it seems like updating the build-optimized that is used by the ionic scripts always saves me when I have these OOM issues with Ionic builds.

@Jahrenski
Copy link

@jayordway When you say you needed to update the webpack.config.js, how did you do so?
Where is this located?

@SeanStayn
Copy link

SeanStayn commented May 20, 2019

I had the same issue. My problem was, that I have imported the whole firebase library, instead of only the components I needed.

So, if you get the following warning:

It looks like you're using the development build of the Firebase JS SDK.
When deploying Firebase apps to production, it is advisable to only import
the individual SDK components you intend to use.

For the module builds, these are available in the following manner
(replace with the name of a component - i.e. auth, database, etc):

CommonJS Modules:
const firebase = require('firebase/app');
require('firebase/');

ES Modules:
import firebase from 'firebase/app';
import 'firebase/';

You have to change your import:

Initialize your firebase:

import { initializeApp } from "firebase/app";
initializeApp(firebaseConfig);

Using firestore, auth, ...:

import firebase from 'firebase/app';
import 'firebase/firestore';
import 'firebase/auth';

and if the warning is gone, you should be able to build with prod flag!

@pitamash
Copy link

pitamash commented Dec 9, 2019

In Packages scripts add
"scripts": {
"ionic:build": "node --max-old-space-size=8192 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build"
},

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests