Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
564 views
in Technique[技术] by (71.8m points)

node.js - Angular 11 compilation target es5 causes JavaScript heap out of memory issue

Recently upgraded to angular 11 and stumbled upon an issue during running npm test in my gitlab pipeline, the issue is only when running npm test, npm build prod seems to work fine.

Below information about the env.

Deploy image has Node 14 LTS

angular CLI: 11.0.5

Target:es5

I've tried to run ng test with more memory, it didn't help

node --max_old_space_size=5000 ./node_modules/@angular/cli/bin/ng test --code-coverage

noticed when changing the target to es2015 or es6 npm test seems to work, but I don't want to make this change is causing some other functionality to break in my application.

Here's a screenshot of the error: error


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use this command to Serve & Build

node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng serve

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

node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng test 

As stated here

Target signifies which target of JavaScript should be emitted from the given TypeScript.

Examples:

target:es5 ()=>null will become function(){return null} as ES5 doesn't have arrow functions.

target:es6 ()=>null will become ()=>null as ES6 has arrow functions.

this post

So Using ES5 As target makes generating more code and Transpilation process heavier


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...