Repository navigation
Closed
Labels
area: coreIssues related to the framework runtimefreq2: mediummemory leakIssue related to a memory leaktype: bug/fix
Description
AoT compilation resulting in " JavaScript heap out of memory" error
I am trying to compile my project by following the AoT guide available on angular.io
Below is my typesccript configuration file for aot
{
"compilerOptions": {
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"module": "es2015",
"moduleResolution": "node",
"noImplicitAny": false,
"suppressImplicitAnyIndexErrors": true,
"noEmitOnError": true,
"removeComments": true,
"sourceMap": false,
"target": "es5",
"outDir": "../content/app/"
},
"angularCompilerOptions": {
"genDir": "aot",
"skipMetadataEmit": true
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}
I am compiling using below command:
D:\MyProject\node_modules\.bin>ngc -p ../../app/tsconfig-aot.json
It takes times in compilation and ends up with below errors:
<--- Last few GCs --->
215225 ms: Mark-sweep 1327.9 (1434.3) -> 1316.1 (1434.3) MB, 1233.5 / 0.0 ms [allocation failure] [GC in old space requested].
216639 ms: Mark-sweep 1316.1 (1434.3) -> 1316.1 (1434.3) MB, 1413.5 / 0.0 ms [allocation failure] [GC in old space requested].
217985 ms: Mark-sweep 1316.1 (1434.3) -> 1320.4 (1403.3) MB, 1346.7 / 0.0 ms [last resort gc].
219337 ms: Mark-sweep 1320.4 (1403.3) -> 1324.6 (1403.3) MB, 1351.5 / 0.0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 00000023CEBCFB61 <JS Object>
1: copyProperties [D:\MyProject\node_modules\typescript\lib\typescript.js:1462] [pc=000001870A3EC95C] (this=000000AAE12C6A41 <an Object with map 00000279F6259FA1>,source=000002E70921E389 <an Object with map 00000279F62D8539>,target=000002ED3C5C7691 <an Object with map 000000D6F40CD1C9>)
2: objectTypeRelatedTo [D:\MyProject\node_modules\typescript\lib\typescript.js:...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
D:\MyProject\node_modules\.bin>
The project I am trying to compile has 467 files.
Reacted by Lazar Ljubenović
Metadata
Metadata
Assignees
Labels
area: coreIssues related to the framework runtimefreq2: mediummemory leakIssue related to a memory leaktype: bug/fix
Activity
DzmitryShylovich commentedon Oct 9, 2016
Hello, we reviewed this issue and determined that it doesn't fall into the bug report or feature request category. This issue tracker is not suitable for support requests, please repost your issue on StackOverflow using tag
angular.If you are wondering why we don't resolve support issues via the issue tracker, please check out this explanation.
naveedahmed1 commentedon Oct 9, 2016
Are you sure its not a bug in AoT compiler?
lazarljubenovic commentedon Oct 9, 2016
Even if it really was a bug, you still have to fill out the template which was presented to you while opening this issue (which you apparently just deleted).
singhjusraj commentedon Oct 28, 2016
Anyone found any solution to this?
ngc runs fine for the first time when things are in JIT mode in main.ts, after first run, I change main,ts to AoT mode.
Then ngc takes a while to compile and the process ends up out of memory.
I couldn't find a solution anywhere
Questions on StackOverflow are unanswered.
I've tried compiling on both Windows and Mac and the process runs out of memory between 1400MB - 1460MB.
It's been over a month for me and there is still no solution to this problem.
Any help will be appreciated thanks..
alexeagle commentedon Oct 28, 2016
How about giving node more memory by setting
--max_old_space_size?singhjusraj commentedon Oct 28, 2016
how can I do that along with ngc?
I've tried
node --max-old-space-size=2048 ./node_modules/.bin/ngc -p tsconfig.jsonIt doesn't work
alexeagle commentedon Oct 28, 2016
Hmm, you could give it more memory than that, but perhaps there's something about the application you're building that causes ngc to leak memory or consume a great amount of memory.
We build angular itself and haven't seen this, but we don't have any project that compiles a very large number of components in a single pass.
Any idea how we can reproduce the issue?
singhjusraj commentedon Oct 28, 2016
@alexeagle thanks for helping me out here.
In my previous comment I meant I'm unable to assign more memory to node. I'm probably not doing it correctly on command line.
here is my script in package.json
"scripts": { "ngc": "node --max-old-space-size=2048 ./node_modules/.bin/ngc -p tsconfig.json" },when I do npm run ngc its gives syntax error as following:
`C:\Users\sukhdeep\Documents\Angular\gd_dev_server\node_modules.bin\ngc:2
basedir=$(dirname "$(echo "$0" | sed -e 's,,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)
at Function.Module._load (module.js:300:12)
at Function.Module.runMain (module.js:441:10)
at startup (node.js:139:18)
at node.js:974:3
`
I'm probably not doing it right.
About the project size, Yes I'll consider my project large as there is lot of HTML in the DOM and there is lot of two way data binding. My aot folder after first ngc compile comes at 15.8MB in size.
@naveedahmed1 you have any input on your project size?
I have another project which is written in exactly the same way, (I've followed proper typescript syntaxes and Angular best practices in both) but has far fewer modules and the aot folder size in that project is just 1.80MB. I don't have any heap issues in that project.
To reproduce, I guess projects that have lot of HTML and data binding are all having this issue.
My repo is private otherwise I would've just given it
naveedahmed1 commentedon Oct 28, 2016
@Sukh9212 after seeing activity on this issue, I just recompiled my project by following the official AoT guide:
https://angular.io/docs/ts/latest/cookbook/aot-compiler.html
I have exact same tsconfig-aot.json file as in above guide except "noImplicitAny": false,.
My App folder has 487 files including components, modules, directive, guards, services and templates.
After compilation aot folder has 344 files and its size is 17.2MB.
After updating main.ts to:
I get the same error which you have mentioned above. One more thing my app is using Lazyloading.
BTW, this is the error after modifying the main.tx
@alexeagle I can email you my app folder, which you would be able to compile. But since it has a dependence on backend in asp.net (which I cann't share) you wont be able to run the project.
@Sukh9212 if you arent using Lazyloading, can you try to compile your project using Angular CLI and see if it works? In angular cli you can compile your project using below command.
ng build --prod --aot
For me its not working since my app is using lazyloading.
singhjusraj commentedon Nov 1, 2016
I'm not using lazy loading since I figured that if I do, ngc just ignores all the lazy loaded modules and doesn't generate AoT code for them. I'm not sure if it's supposed to do that or not.
So not doing that and importing all the modules in my app.module file.
My project isn't Angular CLI based so I won't be able to do that.
It's actually not even a problem of which tool we are using. At the end of it, it's the same ngc compiler and doesn't matter how we invoke it, the process is gonna run out of memory
naveedahmed1 commentedon Nov 2, 2016
Please have a look at below repository:
https://github.com/steveblue/angular2-rollup
and check the Production notes:
https://github.com/steveblue/angular2-rollup#production
It also suggests that there are some issues with ngc when using for large projects and it recommends using Closure Compiler after compiling with ngc.
@vicb can you please help on this?
singhjusraj commentedon Nov 2, 2016
I think closure compiler isn't ready yet for Angular 2 see issue #8550 and this link
Even if closure compiler works, still I would like ngc to do the entire job that it is supposed to do as it is demonstrated in the official tutorials.
Angular 2 isn't in beta or RC anymore, but we still can't generate a production build out of it.
Waiting for it for over a month and half now.
singhjusraj commentedon Nov 3, 2016
OK folks here is how I FINALLY compiled my project with ngc
This doesn't work on windows for some reason, but it worked on a mac machine
//first compile with main.ts in JIT mode
./node_modules/.bin/ngc -p tsconfig-aot.json//then change main.ts to AoT mode and run
node --max-old-space-size=8192 ./node_modules/.bin/ngc -p tsconfig-aot.jsonI literally had to go as far as 8192 (8GB) to not run out of memory (it goes as far as 5-6GB for my project)
//then build the rollup bundle
node --max-old-space-size=8192 node_modules/.bin/rollup -c rollup.jsif everything went well, now you should have a production bundle.
I'm not using lazy loading as if I do, ngc just ignores all the lazy loaded modules and does not generate AoT files for them.
My machine is
16 remaining items
alexeagle commentedon Dec 14, 2016
ritzm21 commentedon Feb 10, 2017
Hi all,
I am also facing same heap error in my ionic 2 project as a result of adding many new components, directives in it. Here is the build script for ionic 2 project in package.json:
"scripts": {
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve"
},
And I modified it based on above discussion as below:
"scripts": {
"ionic:build": "node --max-old-space-size=8192 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build",
"ionic:serve": "ionic-app-scripts serve"
},
But I am still facing javascript heap error. Can anybody help me to understand that above modified script is a right approach to increase the heap size for node?
I am using Windows Command Line(cmd) tool to build the ionic 2 app.
ValterSantosMatos commentedon Mar 10, 2017
@ritzm21 actually that worked for my Ionic2 project.
tbosch commentedon Apr 12, 2017
So we need to do 2 things:
ngc). We already do this internally at Google, and we need to find a way to make this work nicely externally as wellNeltherion commentedon May 8, 2017
any update on this? I used 8 GBs for a simple Bootstrap project and even 8 GBs couldn't do it!
the command that worked for me is :
node --max-old-space-size=8192 node_modules/rollup/bin/rollup -c rollup-config.jsdamiandennis commentedon Nov 26, 2017
I need to allocate 5GB just to compile a medium sized app.
Koslun commentedon Nov 27, 2017
For everyone posting their results I think a more detailed build configuration and project information is needed to get any real insight.
Rollup, Webpack and other bundlers each have their own overhead, changing also vastly depending on version and configuration, including for instance which webpack plugins are used and how they are configured. Angular version is also important to understand what angular compiler is used. Where both the bundler and the angular compiler can consume a great amount of RAM. See an example breakdown here for meeting
2017-11-21: https://docs.google.com/document/d/1wMHjLdXrcGw-8N50mJqqiyFA_upkc6_fTd2vEhOM0-k/pubFollowing a larger regression for angular-cli 1.5, in terms of memory usage, reducing the memory usage is being actively worked on, see: angular/angular-cli#5618. Though this largely does not cover optimizing the angular compiler.
This has partly added to
Webpacks ModuleConcatenationPluginbeing heavily optimized in terms of RAM usage. See webpack/webpack#5992 and webpack/webpack-sources#30.IgorMinar commentedon Dec 22, 2017
It seems that this bug ended up being the catch all place for all kinds of memory related issues. We fixed a whole bunch of them in v4 and then again just after v5.0 was released. Please help us sort these issues out by open new issues with reproductions if you still have memory related problems. Thank you.
angular-automatic-lock-bot commentedon Sep 13, 2019
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.