Skip to content

Angular 7/8 FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory #13734

Description

@arayik-yervandyan

🐞 Bug report

Command (mark with an x)

- [ ] new
- [X] build
- [ ] serve
- [ ] test
- [ ] e2e
- [ ] generate
- [ ] add
- [ ] update
- [ ] lint
- [ ] xi18n
- [ ] run
- [ ] config
- [ ] help
- [ ] version
- [ ] doc

Description

With the last merge project build process is not working. I get failure that is pasted below.
Tried to change --max-old-space-size=4096 still not working.
Any suggestions what this can be ?

🔬 Minimal Reproduction

run command ng build --prod
in angular.json file we have

"production": {
	"optimization": true,
	"outputHashing": "all",
	"sourceMap": false,
	"extractCss": true,
	"namedChunks": false,
	"aot": true,
	"extractLicenses": true,
	"vendorChunk": false,
	"buildOptimizer": true,
	"fileReplacements": [
	{
		"replace": "src/environments/environment.ts",
		"with": "src/environments/environment.prod.ts"
	}
	]
},

🔥 Exception or Error

Here is the log file.

{ Error: Command failed: ng build --prod --configuration=config --output-path=test --base-href=/test/
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
 1: 0x8dbaa0 node::Abort() [ng build --prod --configuration=config --output-path=test --base-href=/test/]
 2: 0x8dbaec  [ng build --prod --configuration=config --output-path=test --base-href=/test/]
 3: 0xad83de v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [ng build --prod --configuration=config --output-path=test --base-href=/test/]
 4: 0xad8614 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [ng build --prod --configuration=config --output-path=test --base-href=/test/]
 5: 0xec5c42  [ng build --prod --configuration=config --output-path=test --base-href=/test/]
 6: 0xec5d48 v8::internal::Heap::CheckIneffectiveMarkCompact(unsigned long, double) [ng build --prod --configuration=config --output-path=test --base-href=/test/]
 7: 0xed1e22 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [ng build --prod --configuration=config --output-path=test --base-href=/test/]
 8: 0xed2754 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [ng build --prod --configuration=config --output-path=test --base-href=/test/]
 9: 0xed53c1 v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationSpace, v8::internal::AllocationAlignment) [ng build --prod --configuration=config --output-path=test --base-href=/test/]
10: 0xe9d636  [ng build --prod --configuration=config --output-path=test --base-href=/test/]
11: 0xeafee7 v8::internal::Factory::NewLoadHandler(int) [ng build --prod --configuration=config --output-path=test --base-href=/test/]
12: 0xf2f4db v8::internal::LoadHandler::LoadFromPrototype(v8::internal::Isolate*, v8::internal::Handle<v8::internal::Map>, v8::internal::Handle<v8::internal::JSReceiver>, v8::internal::Handle<v8::internal::Smi>, v8::internal::MaybeHandle<v8::internal::Object>, v8::internal::MaybeHandle<v8::internal::Object>) [ng build --prod --configuration=config --output-path=test --base-href=/test/]
13: 0xf36d1f v8::internal::LoadIC::ComputeHandler(v8::internal::LookupIterator*) [ng build --prod --configuration=config --output-path=test --base-href=/test/]
14: 0xf3d94c v8::internal::LoadIC::UpdateCaches(v8::internal::LookupIterator*) [ng build --prod --configuration=config --output-path=test --base-href=/test/]
15: 0xf3dffc v8::internal::LoadIC::Load(v8::internal::Handle<v8::internal::Object>, v8::internal::Handle<v8::internal::Name>) [ng build --prod --configuration=config --output-path=test --base-href=/test/]
16: 0xf42935 v8::internal::Runtime_LoadIC_Miss(int, v8::internal::Object**, v8::internal::Isolate*) [ng build --prod --configuration=config --output-path=test --base-href=/test/]
17: 0x235e3925be1d

🌍 Your Environment


Angular CLI: 7.3.1
Node: 10.15.1
OS: linux x64
Angular: 7.2.6
... animations, common, compiler, compiler-cli, core, forms
... http, platform-browser, platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.13.2
@angular-devkit/build-angular     0.13.2
@angular-devkit/build-optimizer   0.13.2
@angular-devkit/build-webpack     0.13.2
@angular-devkit/core              7.3.2
@angular-devkit/schematics        7.3.1
@angular/cdk                      7.3.3
@angular/cli                      7.3.1
@ngtools/webpack                  7.3.2
@schematics/angular               7.3.1
@schematics/update                0.13.1
rxjs                              6.4.0
typescript                        3.1.6
webpack                           4.29.0

Activity

  1. alan-agius4 commented on Feb 21, 2019

    @alan-agius4
    Collaborator

    Hi, in the error stack trace, it seems that you are using a different configuration from "production", can you kindly share that configuration?

  2. arayik-yervandyan commented on Feb 21, 2019

    @arayik-yervandyan
    Author

    Sorry for mismatch here is configuration params that you need

    "config": {
                  "optimization": true,
                  "outputHashing": "all",
                  "sourceMap": false,
                  "extractCss": true,
                  "namedChunks": false,
                  "aot": true,
                  "extractLicenses": true,
                  "vendorChunk": false,
                  "buildOptimizer": true,
                  "fileReplacements": [
                    {
                      "replace": "src/environments/environment.ts",
                      "with": "src/environments/environment.config.ts"
                    }
                  ]
                }
    
  3. nicobytes commented on Feb 26, 2019

    @nicobytes

    I have the same error:

    screen shot 2019-02-26 at 11 43 52 am

    My env:

    screen shot 2019-02-26 at 11 44 23 am

  4. Bloodcast69 commented on Feb 27, 2019

    @Bloodcast69

    Guys here's described the "workaround" for this problem: #5618

  5. mumairofficial commented on Mar 18, 2019

    @mumairofficial
    • new
    • build
    • serve prod
    • test
    • e2e

    I am facing same issue while ng serve --prod

    Reference Image
    image

  6. themanojshukla commented on Mar 25, 2019

    @themanojshukla

    I to got the same error. NodeJs process uses around 1.5GB of RAM, and after few minutes of attempt to clean/allocate memory, it fails with error.

    image

  7. themanojshukla commented on Mar 26, 2019

    @themanojshukla

    UPDATE :-

    I've seen this issue only on WINDOWS machine particularly. Anyone else, noticed that? Or have got same issue in other machines?

    Note: I tried 2 Windows machine, all tests gave same result. Both machine have same config almost.
    i.e. 8GB RAM/Admin Access For Bash/CMD/PowerShell/ i3 & i5 Processor (quad core, both).

    And, I admit that the project that I'm working on is a MESS in terms of code quality.
    I tried one clean code, full fledged application, ON WINDOWS, it was slower in build process, but worked fine.

    I tried MESSY project's code, it never compile on default node heap allocation (around 1.2 GB, not sure.). It works if I allocate more heap memory to node process, say 5 GB. But, in that case too, it took more than 30 mins to build. I tried the 5 GB node heap option with and without --aot AND/OR --prod .

    Same code when tried on CentOS could instance of 1GB RAM/ Virtual Xenon Processor (1 Core), generates build within 90 Seconds. with and without --aot AND/OR --prod

    I'm not sure, but, looks like problem is with Node Service not with Angular CLI itself, coz I've seen some performance lag in new NodeJS releases after last update (locally on WINDOWS machine only).

    Some observations below.:-

    Even though allocating 5 GB of heap, it never used more than 1.9 GB (max) and allocation process was very slow.. it was increasing RAM consumption 1-2 MB per 3-5 seconds. And, was not using Disk Resource as it used to be in older version. (Disk access was very high previously on WINDOWS machine, but build process was faster without extra RAM allocation. This time, same machine almost same code with some bug fixes, but node was upgraded, disk consumption was lowered but slow build generation.)

    Hope somebody can confirm this.

  8. tibinthomas commented on Mar 27, 2019

    @tibinthomas

    Yes, I am also facing the same issue

  9. sswayney commented on Mar 27, 2019

    @sswayney

    Same issue here running on a Mac book pro. macOs Mojoave. Any environment with production: true

  10. nokhodian commented on Mar 28, 2019

    @nokhodian

    same issue on ubuntu server 18.04, but this solved my problem:
    node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod

  11. themanojshukla commented on Mar 28, 2019

    @themanojshukla

    I've tried uninstalling Angular CLI 7, and installed 6.0.8. verified the downgraded version by ng version, still it breaks with the same error.

    Maybe this could be because of nodeJs too. Coz, I'm building same code in CentOS 7, 1.75GB RAM (with 512MB swap memory), single core processor, and with angular CLI 7, it works there. It is breaking in my 2 windows machines.

    For those, who can't afford allocating more RAM (due to less memory available) can create a SWAP memory from the space available from Hard Drive of system. It'll be little slower, but should work without System Upgrade. I've done the same. 👍

  12. j2L4e commented on Apr 5, 2019

    @j2L4e

    In my case the problem only appears, when building --prod --source-map. The normal --prod build runs just fine.

    Using --max_old_space_size=8192 as suggested by @nokhodian it works with memory consumption peaking at ~3.8GiB during source map generation.

    Build environment:

    Angular CLI: 7.3.8
    Node: 10.15.2
    OS: linux x64
    Angular: 7.2.12
    ... animations, common, compiler, compiler-cli, core, forms
    ... http, language-service, platform-browser
    ... platform-browser-dynamic, router, service-worker
    
    Package                           Version
    -----------------------------------------------------------
    @angular-devkit/architect         0.10.4
    @angular-devkit/build-angular     0.10.4
    @angular-devkit/build-optimizer   0.10.4
    @angular-devkit/build-webpack     0.10.4
    @angular-devkit/core              7.0.4
    @angular-devkit/schematics        7.1.0
    @angular/cdk                      7.3.7
    @angular/cli                      7.3.8
    @angular/flex-layout              7.0.0-beta.19
    @angular/material                 7.3.7
    @angular/pwa                      0.11.0
    @ngtools/webpack                  7.0.4
    @schematics/angular               7.1.0
    @schematics/update                0.13.8
    rxjs                              6.4.0
    typescript                        3.2.4
    webpack                           4.19.1
    
  13. arayik-yervandyan commented on Apr 10, 2019

    @arayik-yervandyan
    Author

    In my angular.json file I have setted "sourceMap": false, but it doesn't helped me. Same issue for prod build

  14. ormico commented on Apr 14, 2019

    @ormico

    just chiming in here with same error message when running ng build when the build is working on a particular scss file

  15. 201 remaining items

  16. error505 commented on May 1, 2020

    @error505

    NodeJS Update to latest version solved it for me.

  17. tussharkhairnar commented on May 2, 2020

    @tussharkhairnar
  18. filipesilva commented on May 27, 2020

    @filipesilva
    Contributor

    Heya all, this issue is pretty old by this point and we're mostly focused on resource usage issues on newer CLI version. This issue also contains several different problems that seem to manifest in similar ways, which makes it hard to zero-in on. If you're still seeing problems like this, please open a new issue with reproduction details.

  19. gayankasun commented on Jun 11, 2020

    @gayankasun

    use
    "build:prod": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng build --configuration=prod", in your package.json file
    1

    this will tell node to exceed default memory allocation by given size in command.

  20. kyle-apex commented on Jun 19, 2020

    @kyle-apex

    If it helps anyone else, when we switched from "@angular-devkit/build-angular": "0.803.26" to "@angular-devkit/build-angular": "0.803.27" it caused memory to run away during prod builds at ~43% build progress. It would get stuck at this step and escalate to >25GB of RAM rather than ~1.5GB.

    When we switched back to "@angular-devkit/build-angular": "0.803.26", it worked again. 0.803.27 is a recent release around 6/11/20, so it would only explain new occurrences of this issue.

  21. Flyrell commented on Jun 26, 2020

    @Flyrell

    Seems like the issue is back with v10 release. Using @angular-devkit/build-angular v0.1000.0 and @angular/* packages v10.0.0.

    Node: v14.1.0
    NPM: 6.14.5

    Stack trace:

    <--- Last few GCs --->
    
    [13013:0x108008000]  2808381 ms: Scavenge 2003.1 (2051.0) -> 2002.5 (2051.5) MB, 4.0 / 0.0 ms  (average mu = 0.117, current mu = 0.045) allocation failure 
    [13013:0x108008000]  2809520 ms: Mark-sweep 2003.3 (2051.5) -> 2002.1 (2051.0) MB, 1132.9 / 0.0 ms  (average mu = 0.073, current mu = 0.026) allocation failure scavenge might not succeed
    [13013:0x108008000]  2809535 ms: Scavenge 2003.1 (2051.0) -> 2002.5 (2051.5) MB, 3.3 / 0.0 ms  (average mu = 0.073, current mu = 0.026) allocation failure 
    
    
    <--- JS stacktrace --->
    
    FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
     1: 0x100bc569b node::Abort() (.cold.1) [/usr/local/bin/node]
     2: 0x1000816b5 node::FatalError(char const*, char const*) [/usr/local/bin/node]
     3: 0x10008181e node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
     4: 0x100180909 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
     5: 0x1001808b3 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
     6: 0x1002a0bfd v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
     7: 0x1002a1f60 v8::internal::Heap::MarkCompactPrologue() [/usr/local/bin/node]
     8: 0x10029f947 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
     9: 0x10029e112 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
    10: 0x1002a60d4 v8::internal::Heap::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
    11: 0x1002a612a v8::internal::Heap::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/local/bin/node]
    12: 0x10028417d v8::internal::Factory::NewFillerObject(int, bool, v8::internal::AllocationType, v8::internal::AllocationOrigin) [/usr/local/bin/node]
    13: 0x1004e7b16 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [/usr/local/bin/node]
    14: 0x10074fe99 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_NoBuiltinExit [/usr/local/bin/node]
    zsh: abort      npm run start

    After upgrading Node.js to v14.4.0 the issue seems to be resolved.

  22. arunmmanoharan commented on Jun 26, 2020

    @arunmmanoharan

    @Flyrell I have the same issue with Nodejs 14.4.0 and Angular 10

  23. stingers commented on Jun 28, 2020

    @stingers

    @Flyrell I have the same issue with Nodejs 14.4.0 and Angular 10 but that not seems resolved

  24. Flyrell commented on Jun 29, 2020

    @Flyrell

    Yes, I was using the dev server for a little more today and the issue still exists.

  25. gvsakhil commented on Jul 1, 2020

    @gvsakhil

    Yes the issue still exists with angular 10 and nodejs 12.16.1 :(

  26. superjulius commented on Jul 1, 2020

    @superjulius

    @Flyrell @gvsakhil Avoid commenting on closed issues that are referring to old versions. There is an opened issue #16860 for NG9, which would be more appropriate.

    Note that there is even now an issue #18087 for Angular 10, which got closed so you can expect some improvements with next release.

  27. angular-automatic-lock-bot commented on Aug 1, 2020

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  28. locked and limited conversation to collaborators on Aug 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions