Angular 7/8 FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
π 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
This issue is the same as https://github.com/angular/angular-cli/issues/5618#issuecomment-450151214, as far as I can tell.
I don't see a lot of things I can follow up and investigate though. @themanojshukla mentioned Windows was taking a lot longer. @j3gb3rt is asking about sass, and I have seen reports in the past about sass making things slower.
Does anyone have a reproduction that we can look at and try to debug?
I have run into this issue on a project that does not use sass. I did some environment testing because I originally thought it was an issue relating to Azure Dev Ops.
Using Azure Dev Ops Pipelines:
- Hosted Linux agent with Node 10: Build succeeds
- Hosted Windows vs2017 Agent with Node 10: Build fails
- Hosted Windows vs2017 Agent with Node 6: Build fails
- Hosted Windows vs2019 Agent with Node 10: Build fails
- Hosted Windows vs2019 Agent with Node 6: Build fails
- Hosted Windows Container Agent with Node 10: Build Failed 5/10 attempts
- Install Build Agent on my dev machine(win10) with Node 10: Build Succeeds
- Install Build Agent on my dev machine(win10) with Node 6: Build Succeeds
- Dev machine(win10) using cmd with Node 10: Build Succeeds
- Dev machine(win10) using cmd with Node 6: Build Succeeds
Yes @filipesilva and @Calidus my projects also don't use sass.
Let me give some more observations...
- The pet project (following best practices as much as can be) I created in around a year ago was working very fine that time ( I don't remember the CLI version I used). Now when I'm building it using
--aot --prodit takes bit more time than before but never breaks. No sass used. - New project (of course production code base & I admit, really really messy codes), it breaks on
--aot --prod. No Sass used. Breaks on windows always. Sometimes works on ubuntu without allocating extra heap on node process, but success rate on ubuntu is 10% say. - Another mid-level project (messy codes), works without extra heap allocation but takes a bit more time on both Windows & Ubuntu.
- Another pet project (following best practices as much as can be) works fine so far.. but very less files to compile, so can't be sure on processing loads.
When running ng build --aot --prod for the first time after machine start/restart. it takes 57seconds. afterwards, 22-25seconds only.
First Run Screenshot..

Second Run Screenshot..

Both are for same project.. and are of while writing this comment.
Hope it helps.
I'm facing the same issue. Every time I build I get "JavaScript heap out of memory". I don't want to use node --max_old_space_size=8192 since this doesn't sounds best practice. Any other way to fix this?
@noopur-dabhi I don't think it is fair to say that using node --max_old_space_size=8192 is not best practice.
It is nothing but allowing NODE process (which is going to build your app now) to use more than DEFAULT heap memory (from your RAM or SWAP area).
And this type of allocation is very very common in most of the app development (especially deployment) process. Example, in Java, if we want to restrict our java app heap usage, we add additional flag like --Xmx64m this means maximum heap memory allowed is 64MB.
So if 'Best Practice' is the only concern, I think it's not a problem using node --max_old_space=8192, this means you are allowing NODE process to use maximum of 8192MB from memory. nothing to do with Best Practice Concern.
This is still crashing for me> any suggestions? I tried "ng build --aot --prod" and "node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod"
- Angular Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200/ ** 92% chunk asset optimization TerserPlugin <--- Last few GCs --->
[9568:000002A08DC547B0] 183499 ms: Mark-sweep 1350.2 (1423.6) -> 1350.2 (1424.1) MB, 952.0 / 0.0 ms (average mu = 0.111, current mu = 0.000) allocation failure GC in old space requested [9568:000002A08DC547B0] 184477 ms: Mark-sweep 1350.2 (1424.1) -> 1350.2 (1424.1) MB, 977.5 / 0.0 ms (average mu = 0.058, current mu = 0.000) last resort GC in old space requested
<--- JS stacktrace --->
==== JS stack trace =========================================
0: ExitFrame [pc: 000001D7B1850481]
Security context: 0x008d8961d9b1
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Writing Node.js report to file: report.20190506.161503.9568.001.json
Node.js report completed
1: 00007FF775E1896A public: __cdecl v8::internal::GCIdleTimeHandler::GCIdleTimeHandler(void) __ptr64+4554
2: 00007FF775DC8956 uv_loop_fork+85542
3: 00007FF775DC941D uv_loop_fork+88301
4: 00007FF7761EE72E void __cdecl v8::internal::FatalProcessOutOfMemory(class v8::internal::Isolate * __ptr64,char const * __ptr64)+798
5: 00007FF7761EE667 void __cdecl v8::internal::FatalProcessOutOfMemory(class v8::internal::Isolate * __ptr64,char const * __ptr64)+599
6: 00007FF7762A2144 public: static bool __cdecl v8::internal::Heap::RootIsImmortalImmovable(int)+14068
7: 00007FF776297F52 public: bool __cdecl v8::internal::Heap::CollectGarbage(enum v8::internal::AllocationSpace,enum v8::internal::GarbageCollectionReason,enum v8::GCCallbackFlags) __ptr64+7234
8: 00007FF776296768 public: bool __cdecl v8::internal::Heap::CollectGarbage(enum v8::internal::AllocationSpace,enum v8::internal::GarbageCollectionReason,enum v8::GCCallbackFlags) __ptr64+1112
9: 00007FF776295C25 public: void __cdecl v8::internal::Heap::CollectAllGarbage(int,enum v8::internal::GarbageCollectionReason,enum v8::GCCallbackFlags) __ptr64+949
10: 00007FF7762A0174 public: static bool __cdecl v8::internal::Heap::RootIsImmortalImmovable(int)+5924
11: 00007FF7763D7E4D private: class v8::internal::HeapObject * __ptr64 __cdecl v8::internal::Factory::AllocateRawArray(int,enum v8::internal::PretenureFlag) __ptr64+61
12: 00007FF7763D87E2 private: class v8::internal::Handle
Unfortunately I am facing with the same issue. Before upgrade to 7+ I was able to builid Angular App on DevOps azure envinorment. Now it's not possible. I'm getting following error:
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory 1: 00007FF7B388F04A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+5114 2: 00007FF7B386A0C6 node::MakeCallback+4518 3: 00007FF7B386AA30 node_module_register+2032 4: 00007FF7B3AF20EE v8::internal::FatalProcessOutOfMemory+846 5: 00007FF7B3AF201F v8::internal::FatalProcessOutOfMemory+639 6: 00007FF7B4012BC4 v8::internal::Heap::MaxHeapGrowingFactor+9556 7: 00007FF7B4009C46 v8::internal::ScavengeJob::operator=+24310 8: 00007FF7B400829C v8::internal::ScavengeJob::operator=+17740 9: 00007FF7B4010F87 v8::internal::Heap::MaxHeapGrowingFactor+2327 10: 00007FF7B4011006 v8::internal::Heap::MaxHeapGrowingFactor+2454 11: 00007FF7B3BCCDB7 v8::internal::Factory::NewFillerObject+55 12: 00007FF7B3C62CC6 v8::internal::WasmJs::Install+29414 13: 0000035C75D5C5C1 npm ERR! code ELIFECYCLE npm ERR! errno 134
@vindemi you are going to need to edit your Build Pipeline. Remove the npm build task and replace it with a command line task with the following script node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prod make sure to set your working directory to the folder with your package.json.
@vindemi you are going to need to edit your Build Pipeline. Remove the npm build task and replace it with a command line task with the following script
node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prodmake sure to set your working directory to the folder with your package.json.
its working thanks
Of note as well is that Node.js 12 automatically configures its memory options based on the available system memory.
Did this solution work for anybody? I still get the same error on VS2017 hosted process on Azure. Here is my YAML for the step. What is the root cause of this? Running this even locally on a beefy I7 I get 100% CPU hit and nearly 5GB of RAM usage. Is there something I need to refactor? I have a bunch of standard components with LESS files.
`steps:
- script: | node --max_old_space_size=8192 $(Build.SourcesDirectory)\node_modules.bin\ng.cmd build --prod displayName: 'Command Line Script' `
Error:
`##[section]Starting: Command Line Script
Task : Command Line Description : Run a command line script using cmd.exe on Windows and bash on macOS and Linux. Version : 2.148.0 Author : Microsoft Corporation Help : More Information
Generating script.
========================== Starting Command Output ===========================
##[command]"C:\windows\system32\cmd.exe" /D /E:ON /V:OFF /S /C "CALL "d:\a_temp\3e7b4265-9fa3-47c6-b6b7-b690af8bcac6.cmd""
Browserslist: caniuse-lite is outdated. Please run next command yarn upgrade caniuse-lite browserslist
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
1: 00007FF747A7F04A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+5114
2: 00007FF747A5A0C6 node::MakeCallback+4518
3: 00007FF747A5AA30 node_module_register+2032
4: 00007FF747CE20EE v8::internal::FatalProcessOutOfMemory+846
5: 00007FF747CE201F v8::internal::FatalProcessOutOfMemory+639
6: 00007FF748202BC4 v8::internal::Heap::MaxHeapGrowingFactor+9556
7: 00007FF7481F9C46 v8::internal::ScavengeJob::operator=+24310
8: 00007FF7481F829C v8::internal::ScavengeJob::operator=+17740
9: 00007FF748200F87 v8::internal::Heap::MaxHeapGrowingFactor+2327
10: 00007FF748201006 v8::internal::Heap::MaxHeapGrowingFactor+2454
11: 00007FF747DBCBE8 v8::internal::Factory::AllocateRawArray+56
12: 00007FF747DC2CFA v8::internal::Factory::NewTransitionArray+58
13: 00007FF7482A6684 v8::internal::CodeStubAssembler::InitializeFunctionContext+26932
14: 00007FF747FDCBFE v8::internal::JSReceiver::GetOwnPropertyDescriptor+17550
15: 00007FF747FDCD69 v8::internal::JSReceiver::GetOwnPropertyDescriptor+17913
16: 00007FF747FDEB9B v8::internal::JSReceiver::GetOwnPropertyDescriptor+25643
17: 00007FF747FCDD94 v8::internal::JSReceiver::class_name+4132
18: 00007FF747FDE2D9 v8::internal::JSReceiver::GetOwnPropertyDescriptor+23401
19: 00007FF747EAACFE v8::internal::LookupIterator::PrepareTransitionToDataProperty+478
20: 00007FF747FD1E11 v8::internal::JSReceiver::class_name+20641
21: 00007FF747DACFE9 v8::internal::wasm::WasmCodeManager::LookupCode+17993
22: 00007FF747DB00A4 v8::internal::wasm::WasmCodeManager::LookupCode+30468
23: 0000023D7E05C5C1
##[error]Cmd.exe exited with code '134'.
##[section]Finishing: Command Line Script`
no it didn't work for me either. Ended up doing a completely different work around.
You may be using a class inside itself of the same name.
Also happens with angular 8 (rc4). When I turn off sourcemaps for production it works again.
With Angular 8, I am unable to build on Azure. I am on the highest tier on Azure Web App with 7GB of RAM (S3). I have tried the --max_old_space_size=8192 trick, but I get the following error.
I have turned of AOT for production. Making my main.js file 3MB instead of 2.5MB, but it does build on Azure. On Azure, Node 10.15.2 is the highest node installed on the machine at the moment.
#
# Fatal process OOM in insufficient memory to create an Isolate
#
<--- Last few GCs --->
<--- JS stacktrace --->
Failed exitCode=-1073741819, command="D:\Program Files (x86)\nodejs\10.15.2\node.exe" --max_old_space_size=8192 node_modules\@angular\cli\bin\ng build myApp --prod --configuration staging --delete-output-path=false --progress=false --outputPath D:\local\Temp\8d6e507f4dfaa02\wwwroot
@johannesjo @jsgoupil I think the issue with 8 has to do with a memory leak on prod builds with differential loading. Can you try disabling it? See https://angular.io/guide/deployment#opting-out-of-differential-loading
cc @alan-agius4
@filipesilva Nope. Doesn't fix anything:
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
I upgraded to Angular 8 this morning and started experiencing this issue. I tried @filipesilva suggestion and it now compiles.
https://angular.io/guide/deployment#opting-out-of-differential-loading
browserslist file
not dead
not IE 9-11
Changed to
dead
IE 9-11
tsconfig.json file
"compilerOptions": {
"target": "es2015"
...
Changed to
"compilerOptions": {
"target": "es5"
...
@johannesjo @jsgoupil are you using sass/scss?
@filipesilva yes.
@gak10100 did you set sourceMap to true in the angular.json?