-
Notifications
You must be signed in to change notification settings - Fork 300
JavaScript heap out of memory #1036
Comments
I also have the same problems |
Hello
I tried several stuff like:
The only which worked for me. Modify:
By adding:
I am on windows. So if you are on linux I guess you have to modify
However this is a tweak. It could be nice to pass this environment variable like this:
Last thing. In some cases it is Keep me posted if it is working for you. |
I just noticed that the origin of the issue is the need of the workaround. Sorry. |
Thanks @speedfl, my issue is also a big app. Maybe would be useful to debug if we could find a way to quantify what a "big" app is... Dunno if running the ionic build command with --verbose could also output the bundle size. Waiting for the Ionic team for some feedback on this.
|
For my app I found the critic threshold. |
same issue here. problem started after adding a big google library |
As I mentioned in the other issue: NB: shebang in linux accepts only one parameter so #!/usr/bin/env node --max_old_space_size=4096` won't work |
Same issue as #1076 With the angular-cli some persons face the same issue too angular/angular-cli#5618 P.S.: Like I said in #1076, I don't face the problem with app-scripts |
@ValterSantosMatos |
@ValterSantosMatos Thanks your work around solved my issue. Also by doing this I had enough memory to show what I think was causing the issue which was typescript. I ended upgrading to typescript to 2.6.1 and I finally can build my production version of my project. |
@ValterSantosMatos i tried the steps as you mentioned, but while running this command |
Hi @MidhunSai looks like you have the wrong typescript version, can you try with the same the ionic team uses: ionic conference app |
i have the same problem and can't make prod build and can't use ionic pro live deployment . tried the steps above and others but failed. i have to release a new version for app stores. please help.
package.json:
i am using custom webpackconfig.js file.
error message.
|
Same problem here: It just happens !! I was debugging in production and in 4 or 5 builds it just started to consume ALL memory no matter how much --max_old_space_size i set it consumes all of it :D build never happens and i am stuck.IONIC is the new JAVA VM --max_old_space_size=16000 |
+1 |
Same. here. I've upped the --max_old_space_size=12000. I waited 3 hours only to get the same out of memory message. I don't know if loading all my lazy loaded pages (22+) will solve the problem, but i'm out of options as I really need the lazy loading. I've updated my CLI (3.19), app-scripts (3.19) and typescript (2.6.2) to the latest recommended, as well as followed ionic doctor. I'm currently on a project with a deadline one month and half away, and I'm really hoping this could be sorted out before then. |
I manage to make it work with the following versions "postinstall": "cd ./node_modules/ && mkdir gapi-angular-client && cp -r ./@gapi/angular-client/* ./gapi-angular-client",
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve",
"build:prod:aot": "ionic build --prod --aot",
"start:docker": "docker-compose up -d --force-recreate",
"build:docker": "docker build -t juice/mobile/aot:latest ."
},
"dependencies": {
"@angular/animations": "5.2.9",
"@angular/common": "5.2.9",
"@angular/compiler": "5.2.9",
"@angular/compiler-cli": "5.2.9",
"@angular/core": "5.2.9",
"@angular/forms": "5.2.9",
"@angular/http": "5.2.9",
"@angular/platform-browser": "5.2.9",
"@angular/platform-browser-dynamic": "5.2.9",
"@gapi/angular-client": "^0.7.172",
"@ionic-native/background-geolocation": "^4.7.0",
"@ionic-native/core": "^4.7.0",
"@ionic-native/facebook": "^4.7.0",
"@ionic-native/geolocation": "^4.7.0",
"@ionic-native/google-maps": "^4.7.0",
"@ionic-native/location-accuracy": "^4.7.0",
"@ionic-native/onesignal": "^4.7.0",
"@ionic-native/secure-storage": "^4.7.0",
"@ionic-native/splash-screen": "4.6.0",
"@ionic-native/status-bar": "4.6.0",
"@ionic/pro": "1.0.20",
"@ionic/storage": "2.1.3",
"@types/node": "^9.6.6",
"angularfire2": "^5.0.0-rc.6.0",
"cordova-android": "7.1.0",
"cordova-browser": "5.0.3",
"cordova-ios": "4.5.4",
"cordova-plugin-device": "^2.0.2",
"cordova-plugin-facebook4": "git+https://github.com/amritk/cordova-plugin-facebook4.git",
"cordova-plugin-geolocation": "^4.0.1",
"cordova-plugin-googlemaps": "^2.2.9",
"cordova-plugin-ionic-keyboard": "^2.0.5",
"cordova-plugin-ionic-webview": "^1.2.0",
"cordova-plugin-mauron85-background-geolocation": "^2.3.5",
"cordova-plugin-request-location-accuracy": "^2.2.2",
"cordova-plugin-secure-storage": "^2.6.8",
"cordova-plugin-splashscreen": "^5.0.2",
"cordova-plugin-statusbar": "^2.4.2",
"cordova-plugin-whitelist": "^1.3.3",
"firebase": "^4.12.1",
"ionic-angular": "3.9.2",
"ionicons": "3.0.0",
"ngx-cache-layer": "^1.6.2",
"onesignal-cordova-plugin": "^2.3.3",
"rxjs": "5.5.8",
"subscriptions-transport-ws": "^0.9.8",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.26"
},
"devDependencies": {
"@ionic/app-scripts": "3.1.8",
"typescript": "~2.6.2"
}, Also if you modify default npm run ionic:build and specify parameters like --prod --aot inside this particular script it will not work.I thik the problem is also related with that app-scripts uses internal to run "npm run ionic:build" Hope this helpa |
Hi @Stradivario Thanks for the feedback. How many pages are you lazy loading? I have 22 (more coming) with 2 imported components. Going through your package.json, are you referring to the "build:prod:aot": "ionic build --prod --aot", my package isn't too different from yours. I've pasted it below. Is there something i'm missing? {
"name": "SomeApp",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "node --max-old-space-size=4096 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build",
"ionic:serve": "ionic-app-scripts serve"
},
"dependencies": {
"@angular/animations": "5.2.9",
"@angular/common": "5.2.9",
"@angular/compiler": "5.2.9",
"@angular/compiler-cli": "5.2.9",
"@angular/core": "5.2.9",
"@angular/forms": "5.2.9",
"@angular/http": "5.2.9",
"@angular/platform-browser": "5.2.9",
"@angular/platform-browser-dynamic": "5.2.9",
"@ionic-native/core": "4.6.0",
"@ionic-native/splash-screen": "4.6.0",
"@ionic-native/status-bar": "4.6.0",
"@ionic/storage": "2.1.3",
"firebase": "^4.12.1",
"ionic-angular": "3.9.2",
"ionicons": "3.0.0",
"ngx-chips": "^1.8.2",
"rxjs": "5.5.8",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.20"
},
"devDependencies": {
"@ionic/app-scripts": "3.1.9",
"typescript": "~2.6.2"
},
"description": "An Ionic project"
}
|
+1 |
For those with large apps, I tried using @bnfrnz 's suggestion at #1426 to use:
instead of and I succeeded in completing my build in ~10-15mins, what normally took 2+hrs I know it might not be ideal to leave out |
+1 |
1 similar comment
+1 |
+1 This seems like this issue has (RE)reared it's ugly head. |
Error When creating Blank Ionic Project `cli packages: (/usr/local/lib/node_modules)
System:
Misc:
`sh-3.2# ionic start mobHiveActive ? What starter would you like to use: blank ? The directory mobHiveActive contains file(s) that could conflict. Would you like to overwrite the directory with this new project? Yes ? Would you like to integrate your new app with Cordova to target native iOS and Android? Yes
Installing dependencies may take several minutes. ✨ IONIC DEVAPP ✨ Speed up development with the Ionic DevApp, our fast, on-device testing mobile app
️--> Install DevApp: https://bit.ly/ionic-dev-app <--
[3013:0x103000000] 348397 ms: Mark-sweep 1349.1 (1407.8) -> 1349.1 (1407.8) MB, 1971.8 / 0.0 ms allocation failure GC in old space requested <--- JS stacktrace ---> ==== JS stack trace ========================================= Security context: 0x3302de0a5879 FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory |
+1 |
1 similar comment
+1 |
Here is my working answer for the issue. It fixed it for myself, but as we all know. A solution for some may not be a solution for many. |
This is happening to me on a particular project when ionic@4.0.0 is installed. Downgrading to 3.20.0 makes the OOM go away. |
I am using the naive plugin of FCM. and I am getting the same error. This issue is ugly as they come. |
+1 |
2 similar comments
+1 |
+1 |
+1 |
this sort of blows my mind :-D is there no professional investigation going on to try and figure out where this massive memory leak is coming from? Or did someone just add |
@pascalwhoop I think the reason this isn't being investigated is that it's a wide range of issues that culminate to cause this. It was investigated by the Firebase team and ultimately deemed to be an Ionic issue that Firebase is inadvertently causing. This seems to have been corrected (for me anyway) by using this solution that I documented, a few comments above. |
This ultimately comes down to the
|
And I assume the optimizejs does the tree shaking (or whatever its called now) which goes through the module tree and since this is a huge tree, its not working out so well right? I fear there is some tweak that needs to be done that causes the complexity to not explode exponentially with increasing tree node count. |
Yes, you are correct. |
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 Change the first line from: I tried values 1024 and 2048, but for my relatively large app I needed 4096. Now I am able to run |
@basvdijk basically you are facing the same problem ;) If you do that is not different than node --max-old-space-size=8192 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build |
@Stradivario It is different, I've tried your command but the result was a significantly larger .apk file than before. 6.9MB over 5.4MB. Modifying the |
I ment the part with heap size |
Found a better solution, to specify NODE env variable before the build: Credits to: https://stackoverflow.com/a/48895989/4919972 |
None of the options worked, |
I have used your solution, but sadly seems that I am stuck in another issue, doesn't matter if I do --prod --release or anything, the IOS version does not release the |
This did the magic for me: |
After spending so much time on searching here and there to tackle this issue I came across this thread and with the help of some above comments I was able to resolve it. Here are the detailed steps along with the images which I did: I went to: Users ▸ {YourUser} ▸ GitHub ▸ {YourIonicAppPath} ▸ node_modules ▸ @Ionic ▸ app-scripts ▸ bin Removed the first line: "#!/usr/bin/env node" and replaced it with:
After making the above change I was able to build the ionic app for both the platforms without any error: ionic cordova build ios --prod --release ionic cordova build android --prod --release At very this moment I have the following versions: ionic -v: CLI 4.6.0 |
I managed to fix this by increasing the max RAM available to the node process: export NODE_OPTIONS=--max_old_space_size=2048 And open a new terminal to make sure the settings have been set by executing echo $NODE_OPTIONS. Just make sure you don't overdo it/have enough RAM left for your other applications. |
If you are using a CI environment, then this solution will not work. We need a permanent fix for this from the Ionic team. Again, solutions exist to bypass this issue, but once you automate your builds stuff gets complicated. Our current solution is to fix @firebase/database to version 0.2.1 and wait for an Ionic fix. |
A little bit awkward but I confirm that html comment can create memory leak |
I'm seeing this issue but when I build the browser version for prod. |
nothing of all solutions worked for me.... i dont have a large app or html comments either... |
I am trying to create the ionic build with Jenkins getting error with command |
Can anyone please tell that how to resolve the JavaScript heap out of memory issue in ionic 5 as it does not have @ionic/app-scripts. How to resolve this issue? Any help would be appreciated. |
work fine for me, many thanks |
Hi there,
I read in another issue that this should had been solved, before so I tried removing the:
"node --max-old-space-size=8192
workaround from my project but still have the same problem. The stack-trace and ionic info bellow. Let me know if anything else is needed.ionic info
global packages:
local packages:
System:
ionic cordova build ios --prod --verbose
[DEBUG] Loading global plugin @ionic/cli-plugin-proxy
[DEBUG] Throwing PLUGIN_NOT_INSTALLED for global @ionic/cli-plugin-proxy
[DEBUG] Loading local plugin @ionic/cli-plugin-cordova
[DEBUG] Loading local plugin @ionic/cli-plugin-ionic-angular
Running app-scripts build: --prod --iscordovaserve --externalIpRequired --nobrowser
[20:08:46] build prod started ...
[20:08:46] clean started ...
[20:08:46] clean finished in 1 ms
[20:08:46] copy started ...
[20:08:46] ngc started ...
[20:09:19] ngc finished in 32.84 s
[20:09:19] preprocess started ...
[20:09:19] deeplinks started ...
[20:09:22] deeplinks finished in 3.67 s
[20:09:22] optimization started ...
[20:09:39] copy finished in 52.56 s
[20:10:04] optimization finished in 41.73 s
[20:10:04] preprocess finished in 45.40 s
[20:10:04] webpack started ...
<--- Last few GCs --->
402717 ms: Mark-sweep 1332.3 (1437.1) -> 1331.6 (1437.1) MB, 1137.5 / 0.0 ms [allocation failure] [GC in old space requested].
403827 ms: Mark-sweep 1331.6 (1437.1) -> 1331.5 (1437.1) MB, 1109.4 / 0.0 ms [allocation failure] [GC in old space requested].
404969 ms: Mark-sweep 1331.5 (1437.1) -> 1340.4 (1421.1) MB, 1141.3 / 0.0 ms [last resort gc].
406115 ms: Mark-sweep 1340.4 (1421.1) -> 1349.5 (1421.1) MB, 1145.4 / 0.0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x3253a08cfb51
2: /* anonymous */ [/Users/Valter/projects/8sec-front-end/node_modules/source-map/lib/source-node.js:~80] [pc=0x40b1c23c541] (this=0x9c85c680801 <JS Function SourceNode (SharedFunctionInfo 0xd26940f131)>,mapping=0x392f564c03b1 <an Object with map 0xc6fc3d4d9f9>)
3: arguments adaptor frame: 3->1
4: InnerArrayForEach(aka InnerArrayForEach) [native array.js:~935] [pc=0x40b1becab8b] (th...
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::Localv8::Value, v8::Localv8::Message) [/usr/local/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
4: v8::internal::Factory::NewUninitializedFixedArray(int) [/usr/local/bin/node]
5: v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::ConvertElementsWithCapacity(v8::internal::Handlev8::internal::JSObject, v8::internal::Handlev8::internal::FixedArrayBase, v8::internal::ElementsKind, unsigned int, unsigned int, unsigned int, int) [/usr/local/bin/node]
6: v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::GrowCapacityAndConvertImpl(v8::internal::Handlev8::internal::JSObject, unsigned int) [/usr/local/bin/node]
7: v8::internal::Runtime_GrowArrayElements(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
8: 0x40b17d079a7
9: 0x40b17d2e9c5
10: 0x40b1c23c541
Abort trap: 6
The text was updated successfully, but these errors were encountered: