ng-packagr: "JavaScript heap out of memory" error occurs when build with lot of sub packages
Type of Issue
[x] Bug Report
[ ] Feature Request
Description
“JavaScript heap out of memory” error occurs when building with 15+ subpackages.
Here is console output and error reports
https://gist.github.com/johnny-mh/897f377424013e7f4b7048971c121b96
This project build successfully with angular7 versions
// angular 7 (works fine)
$ node_modules/.bin/ng-packagr --version
ng-packagr: 4.4.0
@angular/compiler: 7.0.1
rollup: 0.66.6
tsickle: 0.33.1
typescript: 3.1.3
How To Reproduce
Build library with many sub packages.
Expected Behaviour
Expect the build to work even with very many secondary-entrypoints
Version Information
$ node_modules/.bin/ng-packagr --version
ng-packagr: 5.3.0
@angular/compiler: 8.0.2
rollup: 1.16.2
tsickle: 0.35.0
typescript: 3.4.5
package.json
{
"name": "@commerce-ui/ng-modules",
"version": "0.0.0-PLACEHOLDER",
"peerDependencies": {
"@angular/common": "^8.0.1",
"@angular/core": "^8.0.1",
"@commerce-ui/util": "^2.4.0",
"lodash": "^4.17.11"
},
"dependencies": {
"@egjs/agent": "^2.1.5",
"@egjs/flicking": "^2.5.1",
"billboard.js": "^1.9.2",
"@commerce-ui/legacy-lib": "0.0.6"
}
}
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 4
- Comments: 15 (3 by maintainers)
@johnny-mh please keep the issue open. I really think increasing the available memory is not good solution and ng-packagr should improve it’s memory usage.
I’ve investigated a little bit this issue and it seems the oldPrograms cache causing the memory issue.
With cache (original code): memory increase by about 300MiB / entry point and goes up to 6GiB at the end.
When I clear the oldProgram cache after the entry point is built: memory usage goes up to 1.5GiB at the end.
When I clear all the caches after the entry point is built: max memory usage is 1.2GiB and decrease to 300MiB at the end
Still working on the issue, but if you are willing to trade time for less memory usage then patch the
entry-point.transform.jsin yournode_modulesand run theng-packagrdirectly withnode --expose-gc node_modules/.bin/ng-packagr.You can use the patch-package to automatize the patching. It does not work without the manual gc call, the memory for oldPrograms cache will not be deallocated.
Has this issue been adressed in version 9 ?
Giving more and more RAM to Angular builds is not a correct persistent solution.
To some extent this is experienced when having a lot of sub package. At the moment we only use a single process. And hence you’d need to increase the memory limit of that process using
max-old-space-size.