-
Notifications
You must be signed in to change notification settings - Fork 25k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Angular 2 AoT Heep Errors #12184
Comments
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 If you are wondering why we don't resolve support issues via the issue tracker, please check out this explanation. |
Are you sure its not a bug in AoT compiler? |
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). |
Anyone found any solution to this? I couldn't find a solution anywhere It's been over a month for me and there is still no solution to this problem. |
How about giving node more memory by setting |
how can I do that along with ngc? |
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. Any idea how we can reproduce the issue? |
@alexeagle thanks for helping me out here. here is my script in package.json
when I do npm run ngc its gives syntax error as following: SyntaxError: missing ) after argument list 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. |
@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. For me its not working since my app is using lazyloading. |
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. My project isn't Angular CLI based so I won't be able to do that. |
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? |
I think closure compiler isn't ready yet for Angular 2 see issue #8550 and this link |
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 //then change main.ts to AoT mode and run I 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 if 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 |
That's great, but it does indicate that NGC has issues and needs to be optimized for memory usage. In Windows, does this mean that node just ignores max-old-space-size? BTW what is the size of the final bundle? and how long does it now takes to run the app in browser? |
Yes, I believe that ngc does have some memory management issues as I don't think my project is that huge for a compiler to take up 5-6GB of RAM. In windows there are probably some path issues on the command line and the command just errors out as following: `$ node --max-old-space-size=8192 ./node_modules/.bin/ngc -p tsconfig-aot.json SyntaxError: missing ) after argument list I don't think it's a problem with the size of the final bundle for me is 8.2MB, which isn't small I'm okay with the build size for now, but of course I would like it to be smaller than that. |
Both 8.2 Mb bundle size and 3 seconds load time is very large for a live web app. Maybe AoT with support of Lazy loading could give a better bundle and improve load time. |
8.2 MB seems wrong. Can you use the source-map-explorer package to On Thu, Nov 3, 2016 at 8:36 AM Naveed Ahmed notifications@github.com
|
After using the source-map-explorer here is what I get and strangely, if you look at the top of the tree, the size is 927KB which I think should truely be the size of the bundle. But the actual size is 8.2 MB. No idea how. here is my rollup.js file
|
@naveedahmed1 about lazy loading How do you propose that lazy loading will give better bundle and improve loading time? And since the entire idea of generating a rollup bundle is to pack everything in one JS file, how would the router lazy load modules when everything is in one file? Correct me if I'm wrong but the lazy loading is only going to work if you are using a module loader like SystemJS or WebPack. I don't think it is anyway possible to achieve in a rollup bundle |
The concept is, first you split code into lazy loadable units, then use For the discrepancy between file size and reported sourcemap size, try On Thu, Nov 3, 2016 at 11:50 AM Sukhdeep Singh notifications@github.com
|
Looking at the JS bundle doesn't seem to help. It is one enormous minified file. |
@SinghSukhdeep did you find any solution for Windows? It seems that max-old-space-size doesn't have any effect on Windows. |
I haven't tried on Windows since then. I'll let you know if I figure it out. |
One thing I noticed is that the correct option to specify memory limit is max_old_space_size and not max-old-space-size most of the posts I see on internet mention it with hyphens its actually with underscores. I verified it by runing the command node --v8-options. |
On windows you can use this: node --max-old-space-size=8192 node_modules/@angular/compiler-cli/src/main.js -p tsconfig-aot.json |
Also getting this error in my project, yes the project does have a lot of directives but are there really such limitations with ngc? Pushing the --max-old-space-size 16000 does not work for me and that is the max of my Mac. I have couple of 2000 lines files with custom directives, should I try to split the directives and components in more files, will that help at all? |
ngc ought to use less memory. It may take some time before we can address
this.
In the meantime, one approach to try is to compile smaller chunks of the
application at a time. As the application scales, even tsc by itself can
take many seconds, which slows down your development roundtrip. The idea is
to tell your build system about several "libraries", each one lists its
dependent libraries. Then you run both ngc only on one library at a time,
giving it .d.ts and .metadata.json (or now ngsummary.json) files as inputs,
and only generating code for the .ts inputs.
…On Wed, Dec 14, 2016 at 6:53 AM Vladimir Amiorkov ***@***.***> wrote:
Also getting this error in my project, yes the project does have a lot of
directives but are there really such limitations with ngc? Pushing the
--max-old-space-size 16000 does not work for me and that is the max of my
Mac.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#12184 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC5I6mU6IuYxHmPD_5PJOL1qIe4Vp0Uks5rIAL2gaJpZM4KSCLp>
.
|
Hi @alexeagle , Thank you for the prompt response. This is what I was considering to try out but it will not be pretty as I am building a plugin that already has its structure implemented and working without issues and now all I am trying is to make it possible to ship it to npm with the necessary AoT files. I will try to think of something but it would be great if the OOM issues of ngc are resolved as I do see many people facing this. |
A quick followup, I was running nodejs version 6.8.1 and updated to the latest 6.9.2. After that I ran the following script:
and was able to run ngc correctly on my entire project. Previously I did try with |
Great, thanks for that note.
…On Wed, Dec 14, 2016 at 7:57 AM Vladimir Amiorkov ***@***.***> wrote:
@alexeagle <https://github.com/alexeagle>
A quick followup, I was running nodejs version 6.8.1 and updated to the
latest 6.9.2. After that I ran the following script:
"scripts": {
"ngc": "node --max-old-space-size=8192 ./node_modules/.bin/ngc -p tsconfig.json",
"tsc": "tsc -p tsconfig.json",
"prepublish": "npm run tsc && npm run ngc"
}
and was able to run ngc correctly on my entire project. Previously I did
try with --max-old-space-size=16000 and was getting the OOM error, it
looks like the *nodejs 6.8.1 was the cause*.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#12184 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAC5I56D2W8VsziqKrHpRNOiOmcf_gfVks5rIBHvgaJpZM4KSCLp>
.
|
Hi all, And I modified it based on above discussion as below: 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? |
@ritzm21 actually that worked for my Ionic2 project. |
So we need to do 2 things:
|
any update on this? I used 8 GBs for a simple Bootstrap project and even 8 GBs couldn't do it! |
I need to allocate 5GB just to compile a medium sized app. |
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 Following 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 |
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. |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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
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:
The project I am trying to compile has 467 files.
The text was updated successfully, but these errors were encountered: