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

Ionic run android --prod with error Javascript heap out of menory #766

Closed
badboy91vn opened this issue Feb 20, 2017 · 8 comments
Closed

Comments

@badboy91vn
Copy link

badboy91vn commented Feb 20, 2017

Note: for support questions, please use one of these channels:

https://forum.ionicframework.com/
http://ionicworldwide.herokuapp.com/

Short description of the problem:

  1. I run "ionic run android --prod" with error Javascript heap out of menory
  2. When I comment any page code 2 of the 66 pages I imported in app.module.ts and run "Ionic run android --prod", it builds successfully but when I open the app and when i click button menu (MenuController) with error "TypeError: _[t] is not a constructor". Sorry for my bad english

What behavior are you expecting?

execute ionic run android --prod or ionic build android --prod --release with no error.

Steps to reproduce:

  1. I run "ionic run android --prod" or "ionic build android --prod --release" with error Javascript heap out of menory. (run with ios with same error)
    JavaScript heap out of memory
  2. When I remove any 2 page of the 66 pages I imported in app.module.ts and run "Ionic run android --prod", it builds successfully but when I open the app and click button menu with error
    MenuController
    Which @ionic/app-scripts version are you using?
    i use v1.0.0 , v1.1.0 , v.1.1.2, v.1.1.3. All show same error

Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)

ionic info:
Your system information:
Cordova CLI: 6.4.0
Ionic Framework Version: 2.0.1
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.1.3
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Windows 8.1
Node Version: v6.9.2
Xcode version: Not installed

package.json:
{
    "name": "ionic-hello-world",
    "author": "Ionic Framework",
    "homepage": "http://ionicframework.com/",
    "description": "DemoIonic: An Ionic project",
    "private": true,
    "scripts": {
        "clean": "ionic-app-scripts clean",
        "build": "ionic-app-scripts build",
        "ionic:build": "ionic-app-scripts build",
        "ionic:serve": "ionic-app-scripts serve"
    },
    "config": {
        "ionic_experimental_manual_treeshaking": true,
        "ionic_experimental_purge_decorators": true,
        "ionic_uglifyjs": "./config/uglifyjs.config.js"
    },
    "dependencies": {
        "@angular/common": "2.2.1",
        "@angular/compiler": "2.2.1",
        "@angular/compiler-cli": "2.2.1",
        "@angular/core": "2.2.1",
        "@angular/forms": "2.2.1",
        "@angular/http": "2.2.1",
        "@angular/platform-browser": "2.2.1",
        "@angular/platform-browser-dynamic": "2.2.1",
        "@angular/platform-server": "2.2.1",
        "@ionic/storage": "1.1.7",
        "ionic-angular": "2.0.0",
        "ionic-native": "2.5.1",
        "ionicons": "3.0.0",
        "rxjs": "5.0.0-beta.12",
        "zone.js": "0.6.26",
        "sw-toolbox": "3.4.0",
        "@angular/router": "^2.0.0-rc.2",
        "crypto-js": "^3.1.7",
        "es6-shim": "^0.35.0",
        "intl": "^1.2.4",
        "ng2-translate": "5.0.0",
        "reflect-metadata": "^0.1.3",
        "ts-md5": "^1.2.0"
    },
    "devDependencies": {
        "@ionic/app-scripts": "1.1.2",
        "@types/lodash": "4.14.45",
        "typescript": "2.0.9"
    },
    "cordovaPlugins": [
        "cordova-plugin-device",
        "cordova-plugin-console",
        "cordova-plugin-statusbar",
        "cordova-plugin-whitelist",
        "ionic-plugin-keyboard",
        "cordova-sqlite-storage",
        {
            "id": "phonegap-plugin-push",
            "locator": "https://github.com/phonegap/phonegap-plugin-push",
            "variables": {
                "SENDER_ID": "353844722544"
            }
        },
        "cordova-plugin-compat",
        "cordova-plugin-camera",
        "cordova-plugin-crosswalk-webview",
        {
            "id": "cordova-plugin-googlemaps",
            "locator": "https://github.com/phonegap-googlemaps-plugin/cordova-plugin-googlemaps",
            "variables": {
                "API_KEY_FOR_ANDROID": "AIzaSyB3_8DxYg3NahSxxB2iHje1MXfBlsg7a9I",
                "API_KEY_FOR_IOS": "AIzaSyAS6q_-xiNQmSKB6Mn-Kft6ZZpppVQIvc8"
            }
        },
        "cordova-plugin-geolocation",
        "cordova-plugin-x-socialsharing",
        "cordova-plugin-network-information",
        {
            "id": "cordova-plugin-splashscreen",
            "locator": "https://github.com/apache/cordova-plugin-splashscreen"
        },
        {
            "id": "cordova-plugin-sslcertificatechecker",
            "locator": "https://github.com/EddyVerbruggen/SSLCertificateChecker-PhoneGap-Plugin"
        }
    ],
    "cordovaPlatforms": [
        "ios",
        "android"
    ]
}
@danbucholtz
Copy link
Contributor

Wow, that is a huge app! The solution in your PR seems valid. Does it fix the problem for you?

Thanks,
Dan

@badboy91vn
Copy link
Author

badboy91vn commented Feb 20, 2017

@danbucholtz It dont. I added --max_old_space_size=2048 or 8000 in

node_modules\@Ionic\app-scripts\bin\ionic-app-scripts.js

but the error still show up. I do not know I added the correct file anymore.

Code insert:

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

@danbucholtz
Copy link
Contributor

Try it from your package.json scripts section:

"ionic:serve" : "node --max_old_space_size=2048 ./node_modules/.bin/ionic-app-scripts serve"

Same with build. I think that will work for you. Please play around with that and let me know how it goes.

Thanks,
Dan

@badboy91vn
Copy link
Author

badboy91vn commented Feb 21, 2017

@danbucholtz I add this in package.json scripts section:

"ionic:build": "node --max_old_space_size=2048 ./node_modules/.bin/ionic-app-scripts build"

This show me a error.
error

Please help me, thanks!!!

@themastersoda
Copy link

themastersoda commented Feb 23, 2017

@danbucholtz Having the same error when trying to build with --prod flag.

Tried changing max_old_space_size to 2048, even to 4096 did not help. Also, reading through other similar reports, tried to reduce amount of sass color variables, but that did not help either, even with only 3 colors defined, same error appeared. As the error is not very informative, could not trace the part that's causing this.

Tried using all versions of app-scripts from 1.0.0 up to the latest with no luck. As in some other cases, rolling back to app-scripts <= 0.0.46 builds just fine.

My app has over 60 pages, ~20 reusable components and some other stuff like services, pipes, directives, etc., so i guess it could be closely related to the reported issue.

@badboy91vn
Copy link
Author

@themastersoda
You can try ionic-angualor 2.0.1 + ionic--app-script 1.0.0 + update last version of ng2-tranlartor ( It worked for me) or try add --max_old_space_size=2048 in folder "node_modules/.bin/ionic-app-scripts.cmd"

@if EXIST "%~dp0\node.exe" (
"%~dp0\node.exe --max_old_space_size=2048 " "%~dp0..@Ionic\app-scripts\bin\ionic-app-scripts.js" %*
) ELSE (
@SETLOCAL
@set PATHEXT=%PATHEXT:;.JS;=;%
node --max_old_space_size=2048 "%~dp0..@Ionic\app-scripts\bin\ionic-app-scripts.js" %*
)

@themastersoda
Copy link

@badboy91vn i don't use ng2-translator, and I tried all the other things you mentioned, but thanks for help :)

@timothybclayton
Copy link

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<user>\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!

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

4 participants