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

set NODE_OPTIONS=--max-old-space-size=30720 command worked for me.

sunilbcone avatar Oct 14 '19 05:10 sunilbcone

Had the same issue and upgrading node to 12.12 today let me ng build --prod

mac4281 avatar Oct 17 '19 01:10 mac4281

We're using Bitbucket pipelines and we can't increase the memory limit to 8GB. Also our application takes about 7-10min to build and we need the sourceMaps for our Sentry error reports.

UPDATE: running ng update @angular/cli @angular/core solved the problem.

yo-epicdavid avatar Oct 17 '19 18:10 yo-epicdavid

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.

TarasKovalenko avatar Oct 21 '19 18:10 TarasKovalenko

We had the same error on Windows-Comupters, caused by a misconfiguration in angular.json. outputPath was set to a path/drive which doesn't exist and it always ended up into the same error, in Angular 7/8 and with different versions of node.js (12.x).

"architect": {
  "build": {
    "options": {
      "outputPath": "Y:/apps/dist" // this caused "JavaScript heap out of memory"!
    }
  }
}

BeniFreitag avatar Oct 23 '19 09:10 BeniFreitag

We're using Bitbucket pipelines and we can't increase the memory limit to 8GB. Also our application takes about 7-10min to build and we need the sourceMaps for our Sentry error reports.

UPDATE: running ng update @angular/cli @angular/core solved the problem.

Running the ng update worked for me as well. One of the minor point versions must have had a memory leak of some sort. Moving from 8.2.8 to 8.2.11 fixed the issue.

magicjj avatar Oct 23 '19 19:10 magicjj

With the latest versions of node is solved (at least for me). I recommend the team node to use in the package.json constructs Engines: https://docs.npmjs.com/files/package.json#Engines

tailot avatar Nov 08 '19 17:11 tailot

This works for me: https://stackoverflow.com/a/58916640/1077309

Sampath-Lokuge avatar Nov 18 '19 15:11 Sampath-Lokuge

I had a very large object (array of about 100.000 items) causing the builder to crash.

Removing that object solved the problem for me.

(As a workaround I now store the object as a string/json and parse it on runtime.)

joschne avatar Nov 21 '19 15:11 joschne

##[error]Error: Npm failed with return code: 3221226505

PritiMaurya avatar Nov 25 '19 12:11 PritiMaurya

13 verbose stack Error: [email protected] dev_build2019: node --max_old_space_size=8384 ./node_modules/@angular/cli/bin/ng build --configuration=dev 13 verbose stack Exit status 3221226505 13 verbose stack at EventEmitter. (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:332:16) 13 verbose stack at EventEmitter.emit (events.js:210:5) 13 verbose stack at ChildProcess. (C:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14) 13 verbose stack at ChildProcess.emit (events.js:210:5) 13 verbose stack at maybeClose (internal/child_process.js:1021:16) 13 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:283:5) 14 verbose pkgid [email protected] 15 verbose cwd D:\a\1\s\PROP-VIVO-SPA 16 verbose Windows_NT 10.0.14393 17 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js" "run" "dev_build2019" 18 verbose node v12.13.0 19 verbose npm v6.12.0 20 error code ELIFECYCLE 21 error errno 3221226505 22 error [email protected] dev_build2019: node --max_old_space_size=8384 ./node_modules/@angular/cli/bin/ng build --configuration=dev 22 error Exit status 3221226505 23 error Failed at the [email protected] dev_build2019 script. 23 error This is probably not a problem with npm. There is likely additional logging output above. 24 verbose exit [ 3221226505, true ]

PritiMaurya avatar Nov 25 '19 12:11 PritiMaurya

Please provide me the solution for this build problem

PritiMaurya avatar Nov 25 '19 12:11 PritiMaurya

@PritiMaurya , Try below command to generate build

node_modules/.bin/ng build --prod --aot --source-map=false --vendor-chunk=true --output-hashing none

kumaresan-subramani avatar Nov 25 '19 13:11 kumaresan-subramani

@kumaresan-subramani I am getting error FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory after run above cmd

PritiMaurya avatar Nov 25 '19 16:11 PritiMaurya

@kumaresan-subramani do you know about error Npm failed with return code: 3221226505

I am getting this error while build on vsts

PritiMaurya avatar Nov 26 '19 06:11 PritiMaurya

@kumaresan-subramani I am getting error FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory after run above cmd

You can try like this

node --max-old-space-size=4096 ./node_modules/@angular/cli/bin/ng build

kumaresan-subramani avatar Nov 26 '19 07:11 kumaresan-subramani

Check your folder name. If your folder name having spaces, these kind of issues will generate. Rename without spaces and restart your machine. hope it will work.

roneyvia avatar Nov 28 '19 10:11 roneyvia

I don't have any folder name with space

PritiMaurya avatar Nov 28 '19 11:11 PritiMaurya

@PritiMaurya , Try solution suggested over this link. It might help.

kamlesh-cis avatar Dec 02 '19 13:12 kamlesh-cis

I don't have any folder name with space

kindly restart your machine.

roneyvia avatar Dec 03 '19 06:12 roneyvia