Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AOT build fails due to "JavaScript heap out of memory" #5618

Closed
ghost opened this issue Mar 24, 2017 · 427 comments
Closed

AOT build fails due to "JavaScript heap out of memory" #5618

ghost opened this issue Mar 24, 2017 · 427 comments

Comments

@ghost
Copy link

ghost commented Mar 24, 2017

Bug Report or Feature Request (mark with an x)

- [X ] bug report -> please search issues before submitting
- [ ] feature request

Versions.

@angular/cli: 1.0.0
node: 7.7.4
os: win32 x64
@angular/animations: 4.0.0
@angular/common: 4.0.0
@angular/compiler: 4.0.0
@angular/core: 4.0.0
@angular/flex-layout: 2.0.0-rc.1
@angular/forms: 4.0.0
@angular/http: 4.0.0
@angular/material: 2.0.0-beta.2
@angular/platform-browser: 4.0.0
@angular/platform-browser-dynamic: 4.0.0
@angular/router: 4.0.0
@angular/cli: 1.0.0
@angular/compiler-cli: 4.0.0

Repro steps.

ng build --prod --aot

The log given by the failure.

/node_modules/@angular/material/aut 92% chunk asset optimization
<--- Last few GCs --->

[6328:0000016AB4D09F00]  1775597 ms: Mark-sweep 1411.2 (1513.5) -> 1411.0 (1513.5) MB, 1240.6 / 0.0 ms  last resort


<--- JS stacktrace --->

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

Security context: 0000034B0DD266A1 <JS Object>
    2: optimize [0000000FABC02311 <undefined>:5480] [pc=00000082575652C8](this=000000633199A279 <an AST_Call with map 0000014753FA0291>,compressor=00000226DBDECA61 <a Compressor with map 0000032B1EC8F829>)
    3: before [0000000FABC02311 <undefined>:5463] [pc=0000008258C1818D](this=00000226DBDECA61 <a Compressor with map 0000032B1EC8F829>,node=000000633199A279 <an AST_Call with map 0000014753...

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

Desired functionality.

I would like to be able the app using AOT.

Mention any other details that might be useful.

I have tried changing ng.cmd to this:

@IF EXIST "%~dp0\node.exe" (
  "%~dp0\node.exe" --max_old_space_size=8192 "%~dp0\..\@angular\cli\bin\ng" %*
) ELSE (
  @SETLOCAL
  @SET PATHEXT=%PATHEXT:;.JS;=;%
  node --max_old_space_size=8192 "%~dp0\..\@angular\cli\bin\ng" %*
)

and ngc.cmd to:

@IF EXIST "%~dp0\node.exe" (
  "%~dp0\node.exe" --max_old_space_size=8192 "%~dp0\..\@angular\compiler-cli\src\main.js" %*
) ELSE (
  @SETLOCAL
  @SET PATHEXT=%PATHEXT:;.JS;=;%
  node --max_old_space_size=8192 "%~dp0\..\@angular\compiler-cli\src\main.js" %*
)

I have 8GB swap file. The build fails after 20-25 minutes standing on 92% progress.

@filipesilva
Copy link
Contributor

filipesilva commented Mar 24, 2017

This is similar to #1652, but seems localized to AOT compilations. There might be improvements we can do to help.

@filipesilva filipesilva added needs: investigation Requires some digging to determine if action is needed package4: @angular-sdk/webpack labels Mar 24, 2017
@iuristona
Copy link

iuristona commented Mar 24, 2017

I got the same issue too.

So, I tried to build the same project (@angular 4.0.0) using ng-cli 1.0.0-rc.4 and it works fine.
ng build --prod --aot

@angular/cli: 1.0.0-rc.4
node: 6.9.5
os: win32 x64
@angular/common: 4.0.0
@angular/compiler: 4.0.0
@angular/core: 4.0.0
@angular/forms: 4.0.0
@angular/http: 4.0.0
@angular/platform-browser: 4.0.0
@angular/platform-browser-dynamic: 4.0.0
@angular/router: 4.0.0
@angular/cli: 1.0.0-rc.4
@angular/compiler-cli: 4.0.0

@ghost
Copy link
Author

ghost commented Mar 27, 2017

I also want to add that even though I try to increase max_old_space_size by editing ng.cmd and ngc.cmd, it seems like the node.js process never uses more than 1600 MB of RAM according to the process monitor on my system, which is well within the limit i setup of 8192 MB and it still says "out of memory".

@tonny008
Copy link

tonny008 commented Mar 27, 2017

I have the same issue. my project works on cli rc.4. it fails when ng build --prod after update to 1.0.0.

@aminebizid
Copy link

I'm so afraid there will be no solution for this issue.
I reverted to rc.2 because of this :(

@efstathiosntonas
Copy link

efstathiosntonas commented Mar 28, 2017

In my case, I installed typescript@2.1.6 instead of @~2.2.0 and the memory issue went away. Give it a try.

There is an issue in ~2.2.0 and @angular/language-service 4.0.0 (in my case i use it)

@AngelVlc
Copy link

AngelVlc commented Mar 28, 2017

I've changed max_old_space_size in %AppData%\npm (Windows) and it works for me when launching ng serve with 1.0.0.

@aminebizid
Copy link

@efstahiosntonas are you using ng4?

@efstathiosntonas
Copy link

@Zigzag95 yes, ng4

@elvisbegovic
Copy link
Contributor

same problem here

@ghost
Copy link
Author

ghost commented Mar 28, 2017

Thanks @AngelVlc !

Changing limit in ng.cmd under %appdata% did the trick! Now node.js uses around 4GB of RAM and the build is completed.

@chrisnicola
Copy link

chrisnicola commented Mar 28, 2017

I'm getting OOM errors with @ngtools/webpack 1.3.0 and @angular 4.0.0. This is on OSX and not Windows as well.

<--- Last few GCs --->

   17671 ms: Mark-sweep 1241.3 (1413.6) -> 1241.3 (1413.6) MB, 615.1 / 0.0 ms [allocation failure] [GC in old space requested].
   18286 ms: Mark-sweep 1241.3 (1413.6) -> 1241.3 (1413.6) MB, 614.2 / 0.0 ms [allocation failure] [GC in old space requested].
   18897 ms: Mark-sweep 1241.3 (1413.6) -> 1249.0 (1410.6) MB, 610.8 / 0.0 ms [last resort gc].
   19484 ms: Mark-sweep 1249.0 (1410.6) -> 1256.6 (1410.6) MB, 586.6 / 0.0 ms [last resort gc].


<--- JS stacktrace --->

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

Security context: 0x51588dcfb51 <JS Object>
    1: /* anonymous */ [/Users/chrisnicola/src/wealthbar/node_modules/webpack/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:~28] [pc=0x33d385eb70d4] (this=0xd76ce5e1e71 <a Resolver with map 0x20b5bd9fe3f1>,request=0x3f6f1fa5ec39 <an Object with map 0x1fbc4c2b91c1>,callback=0xfd0ab9f8a9 <JS Function (SharedFunctionInfo 0x395f78d2a061)>)
    2: applyPluginsParallelBailResult1 [/Users/chri...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: node::Abort() [/usr/local/Cellar/node/6.9.1/bin/node]
 2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/Cellar/node/6.9.1/bin/node]
 3: v8::Utils::ReportApiFailure(char const*, char const*) [/usr/local/Cellar/node/6.9.1/bin/node]
 4: v8::Utils::ApiCheck(bool, char const*, char const*) [/usr/local/Cellar/node/6.9.1/bin/node]
 5: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/Cellar/node/6.9.1/bin/node]
 6: v8::internal::Factory::NewInternalizedStringImpl(v8::internal::Handle<v8::internal::String>, int, unsigned int) [/usr/local/Cellar/node/6.9.1/bin/node]
 7: v8::internal::InternalizedStringKey::AsHandle(v8::internal::Isolate*) [/usr/local/Cellar/node/6.9.1/bin/node]
 8: v8::internal::StringTable::LookupKey(v8::internal::Isolate*, v8::internal::HashTableKey*) [/usr/local/Cellar/node/6.9.1/bin/node]
 9: v8::internal::StringTable::LookupString(v8::internal::Isolate*, v8::internal::Handle<v8::internal::String>) [/usr/local/Cellar/node/6.9.1/bin/node]
10: v8::internal::LookupIterator::LookupIterator(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>, v8::internal::LookupIterator::Configuration) [/usr/local/Cellar/node/6.9.1/bin/node]
11: v8::internal::LookupIterator::PropertyOrElement(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>,v8::internal::Handle<v8::internal::Object>, bool*, v8::internal::LookupIterator::Configuration) [/usr/local/Cellar/node/6.9.1/bin/node]
12: v8::internal::Runtime::GetObjectProperty(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Object>) [/usr/local/Cellar/node/6.9.1/bin/node]
13: v8::internal::Runtime_KeyedGetProperty(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/Cellar/node/6.9.1/bin/node]
14: 0x33d384d092a7
[1]    9536 abort      npm start

@marcalj
Copy link

marcalj commented Apr 3, 2017

Same problem here with:

@angular/cli: 1.0.0-rc.2
node: 6.9.2
os: darwin x64
@angular/common: 2.4.10
@angular/compiler: 2.4.10
@angular/core: 2.4.10
@angular/forms: 2.4.10
@angular/http: 2.4.10
@angular/platform-browser: 2.4.10
@angular/platform-browser-dynamic: 2.4.10
@angular/router: 3.4.10
@angular/cli: 1.0.0-rc.2
@angular/compiler-cli: 2.4.10

@Ristaaf
Copy link

Ristaaf commented Apr 19, 2017

I have the same problem when running "ng build -w"
@angular/cli: 1.0.0
node: 7.8.0
@angular/* 4.0.2

setting --max_old_space_size=8192 works for me, but it is not really a good solution since I cannot redistribute it with the source code to my developers.

One note though, there are both a ng.cmd and an ng file (the latter one is an sh file), and if you are in windows as we are both can be used depending on if you run ng from git bash or cmd so both needs to be changed.

My solution to the problem will probably be to change the npm build command from ng build to call a copy of the ng bash file which I distribute with my code.

@omeralper
Copy link

@Ristaaf How did you change the ng file? Where did you add --max_old_space_size in this file? Can you please share your file.

@Ristaaf
Copy link

Ristaaf commented Apr 21, 2017

@omeralper: This is my solution, it requires people to use git bash as terminal if on windows, but it would be easy to change if needed (just use the cmd file instead):

In my project root I have a folder called scripts and in it a file called ng.sh, which is a copy from node_modules/.bin/ng but with more allowed RAM to be used

#!/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=8192 "./node_modules/@angular/cli/bin/ng" "$@"
  ret=$?
else
  node --max_old_space_size=8192 "./node_modules/@angular/cli/bin/ng" "$@"
  ret=$?
fi
exit $ret

Then in my package.json I do:

"scripts": {
    "build-prod": "bash ./scripts/ng.sh build --prod --aot --env=prod"
}

@KeithGillette
Copy link

I am experiencing a similar issue resulting in a JavaScript heap out of memory error when calling ng e2e in a project using:

  • @angular/cli@1.0.1
  • @angular/*@4.1.0
  • node@6.10.2

I was able to create a cross-platform work-around by changing the package.json e2e script entry to:

    "test-browser-e2e-cucumber": "node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng e2e --webdriver-update",

@filipesilva filipesilva added the P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent label May 23, 2017
@speedy32
Copy link

On windows
@if EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" --max_old_space_size=4096 "%~dp0\node_modules@angular\cli\bin\ng" %*
) ELSE (
@SETLOCAL
@set PATHEXT=%PATHEXT:;.JS;=;%
node --max_old_space_size=4096 "%~dp0\node_modules@angular\cli\bin\ng" %*
)

@dakotamurphyucf
Copy link

check this npm package out https://github.com/endel/increase-memory-limit

@isaacplmann
Copy link

I wrote a little script that lets me control the memory limit in the config section of package.json.
https://github.com/isaacplmann/angular-cli-alias

increase-memory-limit looks pretty sweet too. It didn't exist when I wrote my script and it doesn't let you set your own memory limit.

@zackschuster
Copy link

zackschuster commented Jun 1, 2017

i've been able to repro this with a minimal test case using an out-of-the-box cli app; relevant file here.

basically it seems like trying to match a wildcard without specifiers will blow up the app, which is weird since the test case is pulled almost directly from typescript documentation.

note that "*": ["*"] does not crash the app, only "*": ["*", "$dir/*"]

as a workaround, i've manually specified each of my path maps, which is annoying but lets me compile:

"paths": {
  "app.*": ["app/app.*"],
  "app-*": ["app/app-*"],
  "authentication/*": ["app/authentication/*"],
  "core/*": ["app/core/*"],
  "navigation/*": ["app/navigation/*"],
  "pages/*": ["app/pages/*"]
}

@sis0k0
Copy link
Contributor

sis0k0 commented Jun 6, 2017

We also hit that issue in NativeScript when using the @ngtools/webpack plugin with nativescript-dev-webpack. We use tsconfig paths for mapping our tns-core-modules. They look like that:

"paths": {
  "*": [
    "./node_modules/*",
    "./node_modules/tns-core-modules/*"
  ]
}

However, the bundling fails with the mentioned error (JavaScript heap out of memory). Just like @zackschuster , as a workaround we specified each path mapping manually:

"paths": {
  "application": ["node_modules/tns-core-modules/application"],
  "application-settings": ["node_modules/tns-core-modules/application-settings"],
  "camera": ["node_modules/tns-core-modules/camera"],
  "color": ["node_modules/tns-core-modules/color"],
  "connectivity": ["node_modules/tns-core-modules/connectivity"],
  "console": ["node_modules/tns-core-modules/console"],
  "data/*": ["node_modules/tns-core-modules/data/*"],
  "fetch": ["node_modules/tns-core-modules/fetch"],
  "file-system": ["node_modules/tns-core-modules/file-system"],
  "fps-meter": ["node_modules/tns-core-modules/fps-meter"],
  "globals": ["node_modules/tns-core-modules/globals"],
  "http": ["node_modules/tns-core-modules/http"],
  "image-asset": ["node_modules/tns-core-modules/image-asset"],
  "image-source": ["node_modules/tns-core-modules/image-source"],
  "location": ["node_modules/tns-core-modules/location"],
  "platform": ["node_modules/tns-core-modules/platform"],
  "text": ["node_modules/tns-core-modules/text"],
  "timer": ["node_modules/tns-core-modules/timer"],
  "trace": ["node_modules/tns-core-modules/trace"],
  "ui/*": ["node_modules/tns-core-modules/ui/*"],
  "utils/*": ["node_modules/tns-core-modules/utils/*"],
  "xhr": ["node_modules/tns-core-modules/xhr"],
  "xml": ["node_modules/tns-core-modules/xml"]
}

@zackschuster
Copy link

zackschuster commented Jun 6, 2017

@sis0k0 what do your recompile times look like with that setup? i was getting 40-50s recompiles (on an absurdly tiny project) until i dropped the path maps, at which point it dropped to ~2s.

@aminebizid
Copy link

@zackschuster
What do you mean by path maps?

@zackschuster
Copy link

@Zigzag95

"paths": {
 // ...
}

@sis0k0
Copy link
Contributor

sis0k0 commented Jun 6, 2017

@zackschuster, similar times.

@jiminikiz
Copy link

If you are still on Angular 6 and using Docker:

RUN node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build -- configuration=${NG_CONFIGURATION};

This worked for my team's project. We may consider using 4096 or even 2048 if that works for us.

@ndraiman
Copy link

@jiminikiz You can check how much memory the build process takes to determine how much memory you need to allocate to it.

For example, if the process takes at max 3GB RAM, then you can allocate 4GB instead of the 8GB you're allocating now.

@dobrinsky
Copy link

Hi guys,

I am working in an app that is being developed with Visual Studio. How can I set --max_old_space_size=8192 and where?

I am publishing the project with publish option so I don't know where to set it.

Please any help?

p.s. If I comment

"aot": true

(and "buildOptimizer": true because it depends on aot) I can publish the project.

@iyashiyas
Copy link

iyashiyas commented Oct 18, 2018

before i face problem with java heap out of memory
and i run code with increasing memory but i failed with module error..
and i upgraded to angular 6 and successfully build with --prod mode

node --max_old_space_size=8192 'node_modules/@angular/cli/bin/ng' build --prod

Else you can set your angular.json
"build-prod": "node --max_old_space_size=8192 'node_modules/@angular/cli/bin/ng' build --prod ",

and call build-prod in u r command

now i am using --prod its more power full other than aot

Hi guys,

I am working in an app that is being developed with Visual Studio. How can I set --max_old_space_size=8192 and where?

I am publishing the project with publish option so I don't know where to set it.

Please any help?

p.s. If I comment

"aot": true

(and "buildOptimizer": true because it depends on aot) I can publish the project.

@radjivF
Copy link

radjivF commented Oct 19, 2018

I want to test my prod version with

"serve-prod": "ng serve --prod --build-optimizer",

Where can I add --max_old_space_size=819 because right now Im getting

The option '--max_old_space_size' is not registered with the serve command. Run `ng serve --help` for a list of supported options.

Really need some help

Thx

@Moulde
Copy link

Moulde commented Oct 19, 2018

Does this not work for you?
node --max_old_space_size=8192 'node_modules/@angular/cli/bin/ng' build --prod --build-optimizer

The --max_old_space_size argument is for node, not ng

@filipesilva
Copy link
Contributor

Just want to highlight something I said in #6795 (comment) because it happlies here as well:

Increasing the memory limit is not a hack, and something you should expect to do at some point. Node processes have a default memory limit of about 1.7gigs. When a node process starts getting close to the memory limit it needs to spend more and more time doing garbage collection to free up memory, which in turn makes it run more slowly.

Bigger projects will use up more memory than smaller projects so at some point a project will hit the memory limit. I personally use a npm script for this:

"ng-high-memory": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng",

It's hard to act on many of these reports since there is no objective reproduction that we can follow. It's not that we don't believe that builds can be slow. But builds can be slow for many reasons. It's exceedingly likely that the projects that are seeing the most dramatic build times are suffering from some odd problem somewhere in the pipeline that is not a general problem, and for those we really need to reproduce it to fix it.

General performance improvements are of course always helpful, and we try to do them as much as possible. But the absolute best way of getting us to fix issues, especially hard to fix ones, is to offer concrete repros.

@dobrinsky
Copy link

@filipesilva everybody says that we have to use "hack" and solutions, but not where we can put that in an automated publishing file.

Can we use that in angular.json and where?

this is my angular.json right now:

{
  "$schema": "./node_modules/@angular/cli/lib/config/schema.json",
  "version": 1,
  "newProjectRoot": "projects",
  "projects": {
    "ClientApp": {
      "root": "",
      "sourceRoot": "src",
      "projectType": "application",
      "prefix": "app",
      "schematics": {},
      "targets": {
        "build": {
          "builder": "@angular-devkit/build-angular:browser",
          "options": {
            "outputPath": "dist",
            "index": "src/index.html",
            "main": "src/main.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.app.json",
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ],
            "styles": [
              "src/styles.css"
            ],
            "scripts": []
          },
          "configurations": {
            "production": {
              "fileReplacements": [
                {
                  "replace": "src/environments/environment.ts",
                  "with": "src/environments/environment.prod.ts"
                }
              ],
              "optimization": true,
              "outputHashing": "all",
              "sourceMap": false,
              "extractCss": true,
              "namedChunks": false,
              //"aot": true,
              "extractLicenses": true,
              "vendorChunk": false,
              //"buildOptimizer": true
            }
          }
        },
        "serve": {
          "builder": "@angular-devkit/build-angular:dev-server",
          "options": {
            "browserTarget": "ClientApp:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "ClientApp:build:production"
            }
          }
        },
        "extract-i18n": {
          "builder": "@angular-devkit/build-angular:extract-i18n",
          "options": {
            "browserTarget": "ClientApp:build"
          }
        },
        "test": {
          "builder": "@angular-devkit/build-angular:karma",
          "options": {
            "main": "src/test.ts",
            "polyfills": "src/polyfills.ts",
            "tsConfig": "src/tsconfig.spec.json",
            "karmaConfig": "src/karma.conf.js",
            "styles": [
              "src/styles.css"
            ],
            "scripts": [],
            "assets": [
              "src/favicon.ico",
              "src/assets"
            ]
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": [
              "src/tsconfig.app.json",
              "src/tsconfig.spec.json"
            ],
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    },
    "ClientApp-e2e": {
      "root": "e2e/",
      "projectType": "application",
      "targets": {
        "e2e": {
          "builder": "@angular-devkit/build-angular:protractor",
          "options": {
            "protractorConfig": "e2e/protractor.conf.js",
            "devServerTarget": "ClientApp:serve"
          },
          "configurations": {
            "production": {
              "devServerTarget": "ClientApp:serve:production"
            }
          }
        },
        "lint": {
          "builder": "@angular-devkit/build-angular:tslint",
          "options": {
            "tsConfig": "e2e/tsconfig.e2e.json",
            "exclude": [
              "**/node_modules/**"
            ]
          }
        }
      }
    }
  },
  "defaultProject": "ClientApp"
}

where can I put that to make it build?

Thank you very much.

@filipesilva
Copy link
Contributor

@dobrinsky the code sample I showed was an npm script. Those scripts go into the package.json file, under the scripts key:

{
  "name": "my-project",
  "version": "0.0.0",
  "scripts": {
    "ng-high-memory": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng",
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

When you use have that script, you can use npm run ng-high-memory -- followed by the arguments instead of ng inside that project. Always use the double dash before arguments, otherwise they might not be parsed correctly.

@dobrinsky
Copy link

Thank you very much @filipesilva

It still won't work

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'build',
1 verbose cli   '--',
1 verbose cli   '--prod' ]
2 info using npm@6.4.1
3 info using node@v10.10.0
4 verbose run-script [ 'prebuild', 'build', 'postbuild' ]
5 info lifecycle client-app@0.0.0~prebuild: client-app@0.0.0
6 info lifecycle client-app@0.0.0~build: client-app@0.0.0
7 verbose lifecycle client-app@0.0.0~build: unsafe-perm in lifecycle true
8 verbose lifecycle client-app@0.0.0~build: PATH: C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;C:\Users\Andrei\PROJECTS\Angular 6\SIGAD\SIGAD\ClientApp\node_modules\.bin;C:\Python34\;C:\Python34\Scripts;C:\Users\Andrei\algs4\java\bin;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Users\Andrei\.dnx\bin;C:\Program Files\Microsoft DNX\Dnvm\;C:\Program Files\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files (x86)\MiKTeX 2.9\miktex\bin\;C:\Program Files\Microsoft SQL Server\130\Tools\Binn\;C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\110\Tools\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\;C:\Program Files\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files (x86)\Microsoft SQL Server\120\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft SQL Server\120\DTS\Binn\;C:\Program Files\MATLAB\R2016a\runtime\win64;C:\Program Files\MATLAB\R2016a\bin;C:\Program Files\MATLAB\R2016a\polyspace\bin;C:\Program Files (x86)\Microsoft Emulator Manager\1.0\;C:\Program Files\Microsoft\Web Platform Installer\;C:\Program Files\Common Files\Autodesk Shared\;C:\Program Files\dotnet\;C:\Program Files (x86)\GtkSharp\2.12\bin;C:\Program Files (x86)\Skype\Phone\;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\dotnet\;C:\WINDOWS\System32\OpenSSH\;C:\Program Files\nodejs\;C:\Program Files (x86)\Microsoft VS Code\bin;C:\Program Files\Git\cmd;C:\Users\Andrei\algs4\bin;C:\Users\Andrei\AppData\Local\Microsoft\WindowsApps;C:\Users\Andrei\AppData\Local\GitHubDesktop\bin;C:\Users\Andrei\AppData\Roaming\npm;C:\Users\Andrei\.dotnet\tools;%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;C:\Users\Andrei\.nuget\packages\nuget.commandline\4.6.2\tools;C:\Users\Andrei\.nuget\packages\microsoft.codeanalysis.analyzers\1.1.0\tools;C:\Users\Andrei\.nuget\packages\microsoft.entityframeworkcore.tools\2.1.3\tools;C:\Program Files\dotnet\sdk\NuGetFallbackFolder\microsoft.aspnetcore.razor.design\2.1.1\tools;C:\Users\Andrei\.nuget\packages\microsoft.applicationinsights.windowsserver\2.7.2\tools
9 verbose lifecycle client-app@0.0.0~build: CWD: C:\Users\Andrei\PROJECTS\Angular 6\SIGAD\SIGAD\ClientApp
10 silly lifecycle client-app@0.0.0~build: Args: [ '/d /s /c', 'ng build "--prod"' ]
11 silly lifecycle client-app@0.0.0~build: Returned: code: 134  signal: null
12 info lifecycle client-app@0.0.0~build: Failed to exec build script
13 verbose stack Error: client-app@0.0.0 build: `ng build "--prod"`
13 verbose stack Exit status 134
13 verbose stack     at EventEmitter.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:182:13)
13 verbose stack     at ChildProcess.<anonymous> (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:182:13)
13 verbose stack     at maybeClose (internal/child_process.js:962:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:251:5)
14 verbose pkgid client-app@0.0.0
15 verbose cwd C:\Users\Andrei\PROJECTS\Angular 6\SIGAD\SIGAD\ClientApp
16 verbose Windows_NT 10.0.17763
17 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "build" "--" "--prod"
18 verbose node v10.10.0
19 verbose npm  v6.4.1
20 error code ELIFECYCLE
21 error errno 134
22 error client-app@0.0.0 build: `ng build "--prod"`
22 error Exit status 134
23 error Failed at the client-app@0.0.0 build script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 134, true ]

@ImranAhmed
Copy link

I started seeing this on my Azure DevOps Build server after upgrading to Angular 7.

Adding the following to package.json and then calling this from my build task fixed it.

"build-prod": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng build --prod

@sanidz
Copy link

sanidz commented Nov 16, 2018

If you have this problem with quagga js library , pay attention that "@angular/service-worker" is installed before "quagga": "^0.12.1" package.

@mariohmol
Copy link

i could run with optimizejs using node --max-old-space-size=8192 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build --release --prod --minifyjs --minifycss --optimizejs

@HarelM
Copy link

HarelM commented Dec 3, 2018

For people who missed @dakotamurphyucf like I did:
using increase-memory-limit package after running npm install will reduce all need to know where binary files are and will do it for all the files - which in my case is very useful since I'm running both regular build and cordova build.
I'm using it only in my CI build script since locally it runs well.
basically: npm install increase-memory-limit -g
And run the command increase-memory-limit.
Pain is gone! No more suffering (for me at least)...

@marcj
Copy link

marcj commented Dec 6, 2018

Or just use export NODE_OPTIONS=--max_old_space_size=4096 which should fix it as well.

@jatinderkumargupta
Copy link

@marcj this solution worked for me.

I set NODE_OPTIONS for windows with following command:
set NODE_OPTIONS=--max_old_space_size=4096

Installing increase-memory-limit, did not work for me on windows. I have not tried on linux/ubuntu or other OS.

@HarelM
Copy link

HarelM commented Dec 10, 2018

@jatinderkumargupta Please note that it's not enough to install increase-memory-limit, you need to run it also after npm installation of all packages has completed. I'm using windows and it worked for me.

@jatinderkumargupta
Copy link

Thanks @HarelM, I run that like you mentioned, but it did not work for me. May be some other problem then.

@pdemro
Copy link

pdemro commented Dec 20, 2018

In Azure Devops I added a command line task which executes the command below prior to the ng build:

node --max-old-space-size=8192

This seems to have resolved the issue for now..

@bkarv
Copy link

bkarv commented Dec 23, 2018

"build-prod": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng build --prod

@ImranAhmed thanks for the suggestion. However where abouts do you add it in angular.json? If I add it I get an 'Property build-prod' not allowed?

@ImranAhmed
Copy link

@bkarv

Add it to package.json under the 'scripts' section not angular.json.

If you are facing the issue with your Azure DevOps build you can then call this new script command that you just added from your AzureDevops build task.

@bkarv
Copy link

bkarv commented Dec 23, 2018

I tried scripts but got errors. I ended up following the suggestion to export NODE_OPTIONS in OS and it worked. Many thanks

@filipesilva
Copy link
Contributor

Hi all,

This thread was opened a while ago, and over time new memory problems have arisen and been solved. Meanwhile a lot of reports still appear here as comments.

Having all the feedback in a single thread makes it hard to get meaningful reports, or to inform people of what versions the regressions that affect them were fixed.

At the time of writing, there are 450 hidden comments:

image

Having so many hidden comments makes it hard for people to find information in anything but the latest comments. But on the other hand I don't think most people would go through all of the comments anyway. New users that see this thread mostly read the first and latest comments and lose things said in between.

So for the reasons stated above (high volume of comments, hidden comments, hard to report and inform people) I'm also locking this issue to prevent this comment from being lost as new comments come in.

Thank you to everyone that reported and helped diagnose these memory problems. If you encounter any new ones, please open a new issue so we can give that specific regression our full attention and provide a resolution for it.

So I'd like to leave the last comment in this thread as reiterating what I said in #5618 (comment), as I think that is what will help most people that find this issue:

Increasing the memory limit is not a hack, and something you should expect to do at some point. Node processes have a default memory limit of about 1.7gigs. When a node process starts getting close to the memory limit it needs to spend more and more time doing garbage collection to free up memory, which in turn makes it run more slowly.

Bigger projects will use up more memory than smaller projects so at some point a project will hit the memory limit. I personally use a npm script for this:

"ng-high-memory": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng",

npm scripts scripts go into the package.json file, under the scripts key:

{
  "name": "my-project",
  "version": "0.0.0",
  "scripts": {
    "ng-high-memory": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng",
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },

When you use have that script, you can use npm run ng-high-memory -- followed by the arguments instead of ng inside that project. Always use the double dash before arguments, otherwise they might not be parsed correctly.

@angular angular locked as resolved and limited conversation to collaborators Dec 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests