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

Angular 9 Production Build Fails during Optimization Phase (terser out of memory)

Open PMoransais opened this issue 6 years ago • 15 comments

A new Angular 9 app fails during a production build (ng build --prod). The application compiles with ng build and ng serve.

This may be similar to 28175 I also found a suggestion to increase the process memory in Nodes (but I do not know how to do that!). I tried to add memory to node but I saw no difference

copy of the command and response

PS C:\iBreeder Dev\dev.iBreeder.net\iBreeder.com2\iBreeder> ng build Generating ES5 bundles for differential loading... ES5 bundle generation complete.

chunk {polyfills} polyfills-es2015.js, polyfills-es2015.js.map (polyfills) 148 kB [initial] [rendered] chunk {polyfills-es5} polyfills-es5.js, polyfills-es5.js.map (polyfills-es5) 656 kB [initial] [rendered] chunk {main} main-es2015.js, main-es2015.js.map (main) 171 kB [initial] [rendered] chunk {main} main-es5.js, main-es5.js.map (main) 220 kB [initial] [rendered] chunk {public-public-module} public-public-module-es2015.js, public-public-module-es2015.js.map (public-public-module) 2.59 MB [rendered] chunk {public-public-module} public-public-module-es5.js, public-public-module-es5.js.map (public-public-module) 2.92 MB [rendered] chunk {vendor} vendor-es2015.js, vendor-es2015.js.map (vendor) 2.74 MB [initial] [rendered] chunk {vendor} vendor-es5.js, vendor-es5.js.map (vendor) 3.21 MB [initial] [rendered] chunk {runtime} runtime-es2015.js, runtime-es2015.js.map (runtime) 9.02 kB [entry] [rendered] chunk {runtime} runtime-es5.js, runtime-es5.js.map (runtime) 9.02 kB [entry] [rendered] chunk {styles} styles-es2015.js, styles-es2015.js.map (styles) 960 kB [initial] [rendered] chunk {styles} styles-es5.js, styles-es5.js.map (styles) 962 kB [initial] [rendered] Date: 2020-02-22T15:29:29.990Z - Hash: 0851422fb8d5b16cbcd5 - Time: 27659ms PS C:\iBreeder Dev\dev.iBreeder.net\iBreeder.com2\iBreeder> ng build --prod

ERROR in main-es2015.7c0f16d0d0f04d486439.js from Terser RangeError: Maximum call stack size exceeded at Array.push () at Tn.push (C:\iBreeder Dev\dev.iBreeder.net\iBreeder.com2\iBreeder\node_modules\terser\dist\bundle.min.js:1:76200) at AST_Call.transform (C:\iBreeder Dev\dev.iBreeder.net\iBreeder.com2\iBreeder\node_modules\terser\dist\bundle.min.js:1:79125) at C:\iBreeder Dev\dev.iBreeder.net\iBreeder.com2\iBreeder\node_modules\terser\dist\bundle.min.js:1:80514 at AST_Return.transform (C:\iBreeder Dev\dev.iBreeder.net\iBreeder.com2\iBreeder\node_modules\terser\dist\bundle.min.js:1:79182) at C:\iBreeder Dev\dev.iBreeder.net\iBreeder.com2\iBreeder\node_modules\terser\dist\bundle.min.js:1:79313 at l (C:\iBreeder Dev\dev.iBreeder.net\iBreeder.com2\iBreeder\node_modules\terser\dist\bundle.min.js:1:931) at e (C:\iBreeder Dev\dev.iBreeder.net\iBreeder.com2\iBreeder\node_modules\terser\dist\bundle.min.js:1:1251) at Mn (C:\iBreeder Dev\dev.iBreeder.net\iBreeder.com2\iBreeder\node_modules\terser\dist\bundle.min.js:1:79287) at C:\iBreeder Dev\dev.iBreeder.net\iBreeder.com2\iBreeder\node_modules\terser\dist\bundle.min.js:1:81469

Thanks

PMoransais avatar Feb 22 '20 15:02 PMoransais

Node.js version? try to update to LTS, it solves lot of problems with memory leaks.

montella1507 avatar Feb 22 '20 18:02 montella1507

Thanks montella1507.

I reverted to the node version 12.16.1 LTS which is the latest with LTS but it does not solve the problem.

PMoransais avatar Feb 23 '20 17:02 PMoransais

Can you please share the full output of ng version?

alan-agius4 avatar Feb 24 '20 19:02 alan-agius4

Versions were: Angular CLI: 9.0.2 Node: 12.16.1 OS: win32 x64

Angular: 9.0.2 ... animations, cli, common, compiler, core, forms, localize ... platform-browser, platform-browser-dynamic, router Ivy Workspace: Yes

Package Version

@angular-devkit/architect 0.900.2 @angular-devkit/build-angular 0.900.2 @angular-devkit/build-optimizer 0.900.2 @angular-devkit/build-webpack 0.900.2 @angular-devkit/core 9.0.2 @angular-devkit/schematics 9.0.3 @angular/compiler-cli 9.0.1 @angular/language-service 9.0.1 @ngtools/webpack 9.0.2 @schematics/angular 9.0.2 @schematics/update 0.900.2 rxjs 6.5.4 typescript 3.7.5 webpack 4.41.2

I upgraded to latest:

Angular: 9.0.2 ... animations, common, compiler, compiler-cli, core, forms ... language-service, localize, platform-browser ... platform-browser-dynamic, router Ivy Workspace: Yes

Package Version

@angular-devkit/architect 0.900.3 @angular-devkit/build-angular 0.900.3 @angular-devkit/build-optimizer 0.900.3 @angular-devkit/build-webpack 0.900.3 @angular-devkit/core 9.0.3 @angular-devkit/schematics 9.0.3 @angular/cli 9.0.3 @ngtools/webpack 9.0.3 @schematics/angular 9.0.3 @schematics/update 0.900.3 rxjs 6.5.4 typescript 3.7.5 webpack 4.41.2

I get the same error

ERROR in main-es2015.bfaa62b2d910658dbac6.js from Terser RangeError: Maximum call stack size exceeded

PMoransais avatar Feb 25 '20 14:02 PMoransais

#alan-agius4

I created a new project so that you can reproduce the error

https://ibreederdev.visualstudio.com/_git/iBreederWeb

This project has been pared down. As is, ng build compiles without errors but ng build --prod has an error as described in my first post.

ERROR in main-es2015.7c0f16d0d0f04d486439.js from Terser RangeError: Maximum call stack size exceeded

In the project at scr/app/app.module.ts I import:

import { TitleCaseUrlSerializer } from '../common/classes/lib';
TitleCaseUrlSerializer  is a custom class that is used in the providers section

  providers: [
	{ provide: 'BASE_URL', useFactory: getBaseUrl },
	{
		// used to provide case insensitive routing
		provide: UrlSerializer, useClass: TitleCaseUrlSerializer
	}
  ]

If you comment out the second provider for Url serializer, both build and build --prod complete without errors

I hope that helps

PMoransais avatar Feb 25 '20 18:02 PMoransais

#alan-agius4

After posting I added to that text project and it is breaking again. I tried to add memory to the node process

node --max_old_space_size=8192 'node_modules/@angular/cli/bin/ng' build --prod

I did not work!

I can upload the changed project if you need that.

PMoransais avatar Feb 25 '20 19:02 PMoransais

I can upload the changed project if you need that.

That would be helpful, thanks!

alan-agius4 avatar Feb 27 '20 16:02 alan-agius4

You can get the project at

https://ibreederdev.visualstudio.com/_git/iBreederWeb

please check earlier post (3 posts up) for small explanation. After I commented out the code that caused the error I added file to this project and eventually the error appeared again.

PMoransais avatar Feb 27 '20 18:02 PMoransais

You can also check similar issue #17106 in Angular git repo

PMoransais avatar Feb 27 '20 19:02 PMoransais

@PMoransais, Did you forget to push? I am not seeing the code described above in the repo.

alan-agius4 avatar Feb 28 '20 14:02 alan-agius4

I did - sorry

I just pushed but I have added to the project since yesterday - the initial issue with a provider in app.module is commented out. build --prod now breaks in one of the files I have added.

PMoransais avatar Feb 28 '20 15:02 PMoransais

I heard rumors (well more like suggestions on github) that if I downgrade from 9.0.4 to 9.0.2, the problem would go away, seeing this issue here, is bad news to me :/ I get this same error on 9.0.4, I too have different settings but the one thing that breaks the terser is that the main bundle is above 500 KB, which is odd because it has been the case on Angular 8 without issues... somethig in typescript maybe? from version 3.4 to 3.7?

ayyash avatar Mar 02 '20 14:03 ayyash

From what I've seen it appears that angular-devkit/[email protected] still requires TypeScript 3.6, even though the rest of Angular 9.0 supports TypeScript 3.7. Normally it will install 3.6 as local dependency if you choose 3.7 for your project, but in case you override dependency resolution it will fail during the optimisation process.

It looks like it's been updated to TypeScript 3.8 in Angular 9.1-next2, so there probably won't be a special fix for 9.0.

HitkoDev avatar Mar 12 '20 22:03 HitkoDev

Closing as I can no longer access the reproduction.

Please update to the most recent Angular CLI version. If the problem persists after upgrading, please open a new issue, provide a simple repository reproducing the problem, and describe the difference between the expected and current behavior.

alan-agius4 avatar Nov 12 '20 12:11 alan-agius4

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.