Skip to content
This repository was archived by the owner on Aug 7, 2021. It is now read-only.

Java Out of Memory Error when using --env.uglify with --release flag #533

Closed
8 of 9 tasks
ghost opened this issue May 22, 2018 · 1 comment
Closed
8 of 9 tasks

Java Out of Memory Error when using --env.uglify with --release flag #533

ghost opened this issue May 22, 2018 · 1 comment

Comments

@ghost
Copy link

ghost commented May 22, 2018

Issue Checklist

Tell us about the problem

Hi guys how are you, thanks for developing Nativescript.

When I used tns run/build --bundle --env.uglify --env.aot it works fine. But when I add --release, I got the out of memory error. I already increased the --max-old-size but still got the error.

The error was:

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/Users/hyperstacks-002/.nvm/versions/node/v6.11.1/bin/node]
 2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/Users/hyperstacks-002/.nvm/versions/node/v6.11.1/bin/node]
 3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/Users/hyperstacks-002/.nvm/versions/node/v6.11.1/bin/node]
 4: v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag) [/Users/hyperstacks-002/.nvm/versions/node/v6.11.1/bin/node]
 5: v8::internal::TypeFeedbackVector::New(v8::internal::Isolate*, v8::internal::Handle<v8::internal::TypeFeedbackMetadata>) [/Users/hyperstacks-002/.nvm/versions/node/v6.11.1/bin/node]
 6: v8::internal::(anonymous namespace)::EnsureFeedbackVector(v8::internal::CompilationInfo*) [/Users/hyperstacks-002/.nvm/versions/node/v6.11.1/bin/node]
 7: v8::internal::(anonymous namespace)::GenerateBaselineCode(v8::internal::CompilationInfo*) [/Users/hyperstacks-002/.nvm/versions/node/v6.11.1/bin/node]
 8: v8::internal::(anonymous namespace)::GetUnoptimizedCodeCommon(v8::internal::CompilationInfo*) [/Users/hyperstacks-002/.nvm/versions/node/v6.11.1/bin/node]
 9: v8::internal::Compiler::Compile(v8::internal::Handle<v8::internal::JSFunction>, v8::internal::Compiler::ClearExceptionFlag) [/Users/hyperstacks-002/.nvm/versions/node/v6.11.1/bin/node]
10: v8::internal::Runtime_CompileLazy(int, v8::internal::Object**, v8::internal::Isolate*) [/Users/hyperstacks-002/.nvm/versions/node/v6.11.1/bin/node]

Local environment

  • Platform macOS v10.13.4
  • Node version v6.11.1
  • NativeScript CLI version v4.0.2

Project data

  • Platform you are building the app for IOS
  • Node dependencies:
{
  "description": "NativeScript Application",
  "license": "SEE LICENSE IN <your-license-filename>",
  "readme": "NativeScript Application",
  "repository": "<fill-your-repository-here>",
  "nativescript": {
    "id": "org.yudabands.app",
    "tns-ios": {
      "version": "4.0.1"
    }
  },
  "dependencies": {
    "@angular/animations": "~5.0.0",
    "@angular/common": "~5.0.0",
    "@angular/compiler": "~5.0.0",
    "@angular/core": "~5.0.0",
    "@angular/forms": "~5.0.0",
    "@angular/http": "~5.0.0",
    "@angular/platform-browser": "~5.0.0",
    "@angular/platform-browser-dynamic": "~5.0.0",
    "@angular/router": "~5.0.0",
    "angular2-moment": "^1.8.0",
    "lodash": "^4.17.10",
    "moment": "^2.22.1",
    "nativescript-angular": "^5.0.0",
    "nativescript-background-http": "^3.2.2",
    "nativescript-camera": "^4.0.2",
    "nativescript-carousel": "3.1.1",
    "nativescript-drop-down": "^3.2.0",
    "nativescript-facebook": "^2.2.2",
    "nativescript-fancyalert": "^1.2.0",
    "nativescript-feedback": "^1.1.2",
    "nativescript-imagepicker": "^6.0.1",
    "nativescript-ios-uuid": "^1.0.0",
    "nativescript-iqkeyboardmanager": "^1.3.0",
    "nativescript-loading-indicator": "^2.4.0",
    "nativescript-local-notifications": "^2.0.3",
    "nativescript-modal-datetimepicker": "^1.1.0",
    "nativescript-pulltorefresh": "^2.0.3",
    "nativescript-push-notifications": "^1.1.0",
    "nativescript-shimmer": "^2.0.0",
    "nativescript-socket.io": "^0.9.0",
    "nativescript-star-ratings": "^1.0.0",
    "nativescript-theme-core": "~1.0.2",
    "nativescript-tslib": "^1.8.1-beta.4",
    "nativescript-ui-autocomplete": "^3.6.0",
    "nativescript-ui-listview": "^3.5.4",
    "nativescript-vibrate": "^2.0.2",
    "nativescript-videoplayer": "^3.1.0",
    "nativescript-youtubeplayer": "^2.2.6",
    "reflect-metadata": "~0.1.8",
    "rxjs": "^5.5.0",
    "shortid": "^2.2.8",
    "tns-core-modules": "^4.0.1",
    "tns-platform-declarations": "^4.0.0",
    "zone.js": "^0.8.4"
  },
  "devDependencies": {
    "@angular/compiler-cli": "~5.0.0",
    "@ngtools/webpack": "~1.8.2",
    "babel-traverse": "6.26.0",
    "babel-types": "6.26.0",
    "babylon": "6.18.0",
    "copy-webpack-plugin": "~4.0.1",
    "css-loader": "~0.28.7",
    "extract-text-webpack-plugin": "~3.0.0",
    "lazy": "1.0.11",
    "nativescript-dev-typescript": "^0.7.1",
    "nativescript-dev-webpack": "^0.9.0",
    "nativescript-worker-loader": "~0.8.1",
    "raw-loader": "~0.5.1",
    "resolve-url-loader": "~2.1.0",
    "typescript": "~2.4.2",
    "webpack": "~3.8.1",
    "webpack-bundle-analyzer": "^2.8.2",
    "webpack-sources": "~1.0.1"
  }
}
  • Webpack configuration:
<!-- Provide the content of your webpack.config.js. -->
const { resolve, join  } = require("path");

const webpack = require("webpack");
const nsWebpack = require("nativescript-dev-webpack");
const nativescriptTarget = require("nativescript-dev-webpack/nativescript-target");
const CopyWebpackPlugin = require("copy-webpack-plugin");
const ExtractTextPlugin = require("extract-text-webpack-plugin");
const { BundleAnalyzerPlugin } = require("webpack-bundle-analyzer");
const { NativeScriptWorkerPlugin } = require("nativescript-worker-loader/NativeScriptWorkerPlugin");

module.exports = env => {
    const platform = env && (env.android && "android" || env.ios && "ios");
    if (!platform) {
        throw new Error("You need to provide a target platform!");
    }
    const platforms = ["ios", "android"];
    const { snapshot, uglify, report, aot } = env;
    const ngToolsWebpackOptions = { tsConfigPath: "tsconfig.json" };

    const config = {
        context: resolve("./app"),
        target: nativescriptTarget,
        entry: {
            bundle: aot ? "./main.aot.ts" : "./main.ts",
            vendor: "./vendor",
        },
        output: {
            pathinfo: true,
            // Default destination inside platforms/<platform>/...
            path: resolve(nsWebpack.getAppPath(platform)),
            libraryTarget: "commonjs2",
            filename: "[name].js",
        },
        resolve: {
            extensions: [".ts", ".js", ".scss", ".css"],
            // Resolve {N} system modules from tns-core-modules
            modules: [
                "node_modules/tns-core-modules",
                "node_modules",
            ],
            alias: {
                '~': resolve("./app")
            },
            // don't resolve symlinks to symlinked modules
            symlinks: false
        },
        resolveLoader: {
            // don't resolve symlinks to symlinked loaders
            symlinks: false
        },
        node: {
            // Disable node shims that conflict with NativeScript
            "http": false,
            "timers": false,
            "setImmediate": false,
            "fs": "empty",
        },
        module: {
            rules: [
                { test: /\.html$|\.xml$/, use: "raw-loader" },

                // tns-core-modules reads the app.css and its imports using css-loader
                { test: /\/app\.css$/, use: "css-loader?url=false" },
                { test: /\/app\.scss$/, use: ["css-loader?url=false", "sass-loader"] },

                // Angular components reference css files and their imports using raw-loader
                { test: /\.css$/, exclude: /\/app\.css$/, use: "raw-loader" },
                { test: /\.scss$/, exclude: /\/app\.scss$/, use: ["raw-loader", "resolve-url-loader", "sass-loader"] },

                // Compile TypeScript files with ahead-of-time compiler.
                { test: /.ts$/, use: [
                    "nativescript-dev-webpack/moduleid-compat-loader",
                    { loader: "@ngtools/webpack", options: ngToolsWebpackOptions },
                ]},
            ],
        },
        plugins: [
            // Vendor libs go to the vendor.js chunk
            new webpack.optimize.CommonsChunkPlugin({
                name: ["vendor"],
            }),
            // Define useful constants like TNS_WEBPACK
            new webpack.DefinePlugin({
                "global.TNS_WEBPACK": "true",
            }),
            // Copy assets to out dir. Add your own globs as needed.
            new CopyWebpackPlugin([
                { from: "App_Resources/**" },
                { from: "fonts/**" },
                { from: "**/*.jpg" },
                { from: "**/*.png" },
                { from: "**/*.xml" },
            ]),
            // Generate a bundle starter script and activate it in package.json
            new nsWebpack.GenerateBundleStarterPlugin([
                "./vendor",
                "./bundle",
            ]),
            // Support for web workers since v3.2
            new NativeScriptWorkerPlugin(),
            // AngularCompilerPlugin with augmented NativeScript filesystem to handle platform specific resource resolution.
            new nsWebpack.NativeScriptAngularCompilerPlugin(
                Object.assign({
                    entryModule: resolve(__dirname, "app/app.module#AppModule"),
                    skipCodeGeneration: !aot,
                    platformOptions: {
                        platform,
                        platforms,
                        // ignore: ["App_Resources"]
                    },
                }, ngToolsWebpackOptions)
            ),
            // Does IPC communication with the {N} CLI to notify events when running in watch mode.
            new nsWebpack.WatchStateLoggerPlugin(),
        ],
    };
    if (report) {
        // Generate report files for bundles content
        config.plugins.push(new BundleAnalyzerPlugin({
            analyzerMode: "static",
            openAnalyzer: false,
            generateStatsFile: true,
            reportFilename: join(__dirname, "report", `report.html`),
            statsFilename: join(__dirname, "report", `stats.json`),
        }));
    }
    if (snapshot) {
        config.plugins.push(new nsWebpack.NativeScriptSnapshotPlugin({
            chunk: "vendor",
            projectRoot: __dirname,
            webpackConfig: config,
            targetArchs: ["arm", "arm64", "ia32"],
            tnsJavaClassesOptions: { packages: ["tns-core-modules" ] },
            useLibs: false
        }));
    }
    if (uglify) {
        config.plugins.push(new webpack.LoaderOptionsPlugin({ minimize: true }));

        // Work around an Android issue by setting compress = false
        const compress = platform !== "android";
        config.plugins.push(new webpack.optimize.UglifyJsPlugin({
            mangle: { except: nsWebpack.uglifyMangleExcludes },
            compress,
        }));
    }
    return config;
};
@NickIliev NickIliev removed their assignment Aug 1, 2018
@NickIliev
Copy link
Contributor

The issue might occur in some environments where the Java HEAP size is initially set to a smaller amount.

Check this comment on how to increase the heap size.

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

1 participant