ng build fail with 'JavaScript heap out of memory' with patch 6.0.3
Versions
Angular CLI: 6.0.3
Node: 8.11.1
OS: darwin x64 (MacBook Pro 8Go RAM)
Angular: 6.0.2
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router, upgrade
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.6.3
@angular-devkit/build-angular 0.6.3
@angular-devkit/build-optimizer 0.6.3
@angular-devkit/core 0.6.3
@angular-devkit/schematics 0.6.3
@angular/cli 6.0.3
@ngtools/webpack 6.0.3
@schematics/angular 0.6.3
@schematics/update 0.6.3
rxjs 6.1.0
typescript 2.7.2
webpack 4.8.3
Repro steps
ng build --prod
Observed behavior
92% chunk asset optimization UglifyJSPlugin [.. waiting for long time] FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
Desired behavior
Build works
Mention any other details that might be useful (optional)
Back to 6.0.1 and 0.6.1 like few days ago works. For the moment I didn't change the default memory allocate to node.
Maybe it's somehow related to update of rxjs and it's new importing rules? Maybe it adds more work to webpack?
I wouldn't expect that, but maybe. I'll be doing some performance benchmarking soon and be sure to keep an eye out on the memory usage.
@filipesilva I've found an issue...but I don't have words...
That was because of updated lodash types...
After reverting them back from 4.14.109 to 4.14.70 memory usage went down to ~1.4gb and there is no "out of memory" error anymore.
I can't believe it! I didn't even include it in the diff I posted above because I thought it doesn't matter at all! WTF?!
My only assumption is that they added a few recursive types like PartialDeep that consume a lot of memory but I'm not sure about anything in this world anymore.
Well that's odd. But also interesting. Can you give me the lodash before and after versions? Maybe we can come up with a simple repro and pinpoint the problem. A lot of people might be suffering from this. Used lodash imports would also be useful.
You can find before/after versions in the comment above. We import the whole lodash and use quite a lot of it's methods including _.chain.
@filipesilva to summ up:
Node.js v10.1.0 with --max_old_space_size=8192 / webpack v4.8.3 / AoT build without minification:
@types/lodash v4.14.109-2.72gb / ~50 seconds@types/lodash v4.14.70-1.62gb / ~50 seconds
Without max_old_space_size set:
@types/lodash v4.14.109-out of memory error after ~20 minutes@types/lodash v4.14.70-1.33gb / ~52 seconds
P.S. lodash v4.14.70 is not compatible with TS 2.7 out of the box - TS throws error node_modules/@types/lodash/index.d.ts(13154,53): error TS2344: Type 'T' does not satisfy the constraint 'object'. To fix it replace this line with isWeakSet<T extends object>(value?: any): value is WeakSet<T>;.
I have the same problems like @ArnaudBarre . But even with the Update to node v10 our travis prod build with angular 6 fails https://travis-ci.org/utetrapp/geli/builds/395360885#L1108. If anybody has an Idea that would be great!
@PatrickSkowronek try to increase the Node.js heap size using --max_old_space_size flag.
@th0r yes I did, I gave it 4096 Mb which should be enough.
@filipesilva After upgrade to Angular v6, my builds are always out of memory when execute ng build --prod.
But after i remove @types/lodash, the build can be passed. So much thanks for @th0r .
But the build time is still much slower than using Angular v5.(About double times). And I have already closed the build optimizer and using Node.js 10.
My Angular version is 6.0.6. Cli version is 6.0.8. It seems the production build time is the main reason which blocking many users upgrade to new Angular version. About half year ago when i try to upgrade to Angular5, i met out of memory issue when i'm using the production build with AOT. I can't find a solution so i can only wait. I wait for about 2 month and update to the latest Angular cli version, the AOT build works.
BTW, currently if i build the production version in my local, it works. But when i try to build it in the CI(I'm using Appveyor), it will throw out of memory error until i remove @types/lodash as i mentioned above. But the CI build works well with Angular v5 and Cli version 1.7.x. For many scenarios of the deployment, the production build should be happened in the CI environment which means it may not have a very good hardware as your local PC. But it doesn't mean that the build should not be passed in the CI.
@lokyoung @th0r How did you determine it was @types/lodash causing your issue? I don't have those installed, but am having same issue where can build successfully on local machine with memory limit set to 8192, but on appveyor it fails with out of memory exception.
@PTC-JoshuaMatthews update part of dependencies, run build and check memory usage. If it's ok then update another part of dependencies and check memory usage etc.
turn off the sourcemap and we get very good build performance. Angular version: 6.0.6 and 6.0.9
Running NodeJs: 10.1.0 on aws CodeBuild @angular/cli: "6.0.8",
I can confirm that the issue is when using the sourcemap: true configuration flag that causes the problem. turned it off and everything works as expected.
But what if you need source-maps in your prod build - what to do?
@dauledk i would recommend to downgrade the cli to a version where build works. And wait for a fix in a future release.
Hi @stefan-karlsson. Could you point what cli version is working for u. Just now, I have downgraded it to the 6.0.1 and I still have issue.
My solution was to explicitly specify in the tsconfig.ts sourcemap: false for the expected environment.
Even if it's supposed to be set at false by default.
Hi all,
Are you still seeing this with the latest versions? Does anyone have some up to date reproduction instructions that I can follow to see it too?
@filipesilva our project has grown a little and here are the latest results:
Angular CLI: 7.2.3
Node: 10.15.1
OS: darwin x64
Angular: 7.2.2
... animations, common, compiler, compiler-cli, core, forms
... platform-browser, platform-browser-dynamic, router, upgrade
Package Version
-----------------------------------------------------------
@angular-devkit/architect 0.12.3
@angular-devkit/build-angular 0.12.3
@angular-devkit/build-optimizer 0.12.3
@angular-devkit/build-webpack 0.12.3
@angular-devkit/core 7.2.3
@angular-devkit/schematics 7.2.3
@angular/cdk 7.3.0
@angular/cli 7.2.3
@ngtools/webpack 7.2.3
@schematics/angular 7.2.3
@schematics/update 0.12.3
rxjs 6.4.0
typescript 3.1.6
webpack 4.29.0
Build (sourcemaps off, minimizer off):
max_old_space_size=8192: 1.45 mins / 3.57gb mem peakno max_old_space_size: ~1 min / JavaScript heap out of memory error
So I can't see any progress here.