angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

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

Open arayik-yervandyan opened this issue 7 years ago β€’ 205 comments

🐞 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

arayik-yervandyan avatar Feb 21 '19 13:02 arayik-yervandyan

Same with ng8 + node 10.16 + not minitied build(found out that in my case Auth0Lock package causes the problem) On node 12.13 everything builds ok

katyapavlenko avatar Dec 18 '19 09:12 katyapavlenko

I'm facing this problem too. This is my config:

    _                      _                 ____ _     ___
   / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
  / β–³ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
 / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
/_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
               |___/

Angular CLI: 1.6.8
Node: 10.17.0
OS: darwin x64
Angular: 5.2.11
... common, compiler, compiler-cli, core, forms, http
... language-service, platform-browser, platform-browser-dynamic
... router

@angular/animations: 4.4.7
@angular/cli: 1.6.8
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.0.29
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.9.8
@schematics/angular: 0.1.17
typescript: 2.5.3
webpack: 3.10.0

In the Stack Overflow I found this solution. It works, but I don't know if this approach seems correct or make sense.

jpcmf avatar Dec 18 '19 19:12 jpcmf

I updated the node.js to the latest LTS (at this moment 12.13.0) version and everything work perfectly. No need anymore set the max-old-space-size.

This worked for me!

TAharshalcarpenter avatar Dec 20 '19 01:12 TAharshalcarpenter

I updated the node.js to the latest LTS (at this moment 12.13.0) version and everything work perfectly. No need anymore set the max-old-space-size.

This worked for me!

Updating to latest node.js worked for me too!

sefasenturk95 avatar Dec 20 '19 14:12 sefasenturk95

I updated the node.js to the latest LTS (at this moment 12.13.0) version and everything work perfectly. No need anymore set the max-old-space-size.

This worked for me!

MerySantos avatar Jan 02 '20 16:01 MerySantos

I updated the node.js to the latest LTS (at this moment 12.13.0) version and everything work perfectly. No need anymore set the max-old-space-size.

Worked for me too

umairhafeez-r avatar Feb 04 '20 23:02 umairhafeez-r

I updated the node.js to the latest LTS (at this moment 12.13.0) version and everything work perfectly. No need anymore set the max-old-space-size.

Worked for me too

I can confirm, that this is working.

Disane87 avatar Feb 06 '20 09:02 Disane87

Same problem here. Angular 7. Any Node 12.X version.

Works with Node 10.

davidgg avatar Feb 13 '20 18:02 davidgg

Upgrading to 12.x worked for me. Loving Angular less and less each day...

MatricomHQ avatar Feb 16 '20 04:02 MatricomHQ

Every release I recall a presentation at NGConfg by one of the angular members stating something like:

"We have over 400 applications at google and we dogfood angular before we release it into the wild. If any of the applications have to change in order to adapt the update, we don't release it"

I think every single release required some type of update to the code.

As far as I remember, they said that they test the applications to make sure nothing breaks after necessary code upgrades. I believe, upgrading the code to take in the enhancements is anyways inevitable.

But this current issue has nothing to do with that. It's more about application size. If the application size is growing, you will have to increase the heap size for the node process.

umairhafeez-r avatar Mar 05 '20 18:03 umairhafeez-r

Just happened to me after updating from 9.0.3 to 9.0.5

rsivan avatar Mar 07 '20 22:03 rsivan

Hi All.. I was using ubuntu 18.04 EC2 instance to build docker images. This issue is resolved as soon as i change the instance type to t2.medium from t2.micro.

rohithhasher avatar Apr 05 '20 09:04 rohithhasher

I was facing same issue for ng serve,

npm cache clean --force resolve this issue

tussharkhairnar avatar Apr 15 '20 10:04 tussharkhairnar

NodeJS Update to latest version solved it for me.

error505 avatar May 01 '20 20:05 error505

I have resolved by installing Nodejs V12 , I was facing issue with Nodejs V10

On Sat, 2 May 2020 at 01:59, Igor Iric [email protected] wrote:

Node JS Update to latest version solved it for me.

β€” You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/angular/angular-cli/issues/13734#issuecomment-622554387, or unsubscribe https://github.com/notifications/unsubscribe-auth/AH6IJ4PME7KZY3J7J3ARITDRPMWLXANCNFSM4GY5SKAQ .

tussharkhairnar avatar May 02 '20 07:05 tussharkhairnar

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.

filipesilva avatar May 27 '20 16:05 filipesilva

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.

gayankasun avatar Jun 11 '20 07:06 gayankasun

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.

kyle-apex avatar Jun 19 '20 13:06 kyle-apex

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.~~

Flyrell avatar Jun 26 '20 11:06 Flyrell

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

arunmmanoharan avatar Jun 26 '20 14:06 arunmmanoharan