-
Notifications
You must be signed in to change notification settings - Fork 12k
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
AOT build fails due to "JavaScript heap out of memory" #5618
Comments
This is similar to #1652, but seems localized to AOT compilations. There might be improvements we can do to help. |
I got the same issue too. So, I tried to build the same project (@angular 4.0.0) using ng-cli 1.0.0-rc.4 and it works fine. @angular/cli: 1.0.0-rc.4 |
I also want to add that even though I try to increase |
I have the same issue. my project works on cli rc.4. it fails when ng build --prod after update to 1.0.0. |
I'm so afraid there will be no solution for this issue. |
In my case, I installed [email protected] instead of @~2.2.0 and the memory issue went away. Give it a try. There is an issue in ~2.2.0 and @angular/language-service 4.0.0 (in my case i use it) |
I've changed max_old_space_size in %AppData%\npm (Windows) and it works for me when launching ng serve with 1.0.0. |
@efstahiosntonas are you using ng4? |
@Zigzag95 yes, ng4 |
same problem here |
Thanks @AngelVlc ! Changing limit in |
I'm getting OOM errors with
|
Same problem here with: @angular/cli: 1.0.0-rc.2 |
I have the same problem when running "ng build -w" setting --max_old_space_size=8192 works for me, but it is not really a good solution since I cannot redistribute it with the source code to my developers. One note though, there are both a ng.cmd and an ng file (the latter one is an sh file), and if you are in windows as we are both can be used depending on if you run ng from git bash or cmd so both needs to be changed. My solution to the problem will probably be to change the npm build command from ng build to call a copy of the ng bash file which I distribute with my code. |
@Ristaaf How did you change the ng file? Where did you add --max_old_space_size in this file? Can you please share your file. |
@omeralper: This is my solution, it requires people to use git bash as terminal if on windows, but it would be easy to change if needed (just use the cmd file instead): In my project root I have a folder called scripts and in it a file called ng.sh, which is a copy from node_modules/.bin/ng but with more allowed RAM to be used
Then in my package.json I do:
|
I am experiencing a similar issue resulting in a
I was able to create a cross-platform work-around by changing the
|
check this npm package out https://github.com/endel/increase-memory-limit |
I wrote a little script that lets me control the memory limit in the config section of
|
i've been able to repro this with a minimal test case using an out-of-the-box cli app; relevant file here. basically it seems like trying to match a wildcard without specifiers will blow up the app, which is weird since the test case is pulled almost directly from typescript documentation. note that as a workaround, i've manually specified each of my path maps, which is annoying but lets me compile: "paths": {
"app.*": ["app/app.*"],
"app-*": ["app/app-*"],
"authentication/*": ["app/authentication/*"],
"core/*": ["app/core/*"],
"navigation/*": ["app/navigation/*"],
"pages/*": ["app/pages/*"]
} |
We also hit that issue in NativeScript when using the "paths": {
"*": [
"./node_modules/*",
"./node_modules/tns-core-modules/*"
]
} However, the bundling fails with the mentioned error (JavaScript heap out of memory). Just like @zackschuster , as a workaround we specified each path mapping manually: "paths": {
"application": ["node_modules/tns-core-modules/application"],
"application-settings": ["node_modules/tns-core-modules/application-settings"],
"camera": ["node_modules/tns-core-modules/camera"],
"color": ["node_modules/tns-core-modules/color"],
"connectivity": ["node_modules/tns-core-modules/connectivity"],
"console": ["node_modules/tns-core-modules/console"],
"data/*": ["node_modules/tns-core-modules/data/*"],
"fetch": ["node_modules/tns-core-modules/fetch"],
"file-system": ["node_modules/tns-core-modules/file-system"],
"fps-meter": ["node_modules/tns-core-modules/fps-meter"],
"globals": ["node_modules/tns-core-modules/globals"],
"http": ["node_modules/tns-core-modules/http"],
"image-asset": ["node_modules/tns-core-modules/image-asset"],
"image-source": ["node_modules/tns-core-modules/image-source"],
"location": ["node_modules/tns-core-modules/location"],
"platform": ["node_modules/tns-core-modules/platform"],
"text": ["node_modules/tns-core-modules/text"],
"timer": ["node_modules/tns-core-modules/timer"],
"trace": ["node_modules/tns-core-modules/trace"],
"ui/*": ["node_modules/tns-core-modules/ui/*"],
"utils/*": ["node_modules/tns-core-modules/utils/*"],
"xhr": ["node_modules/tns-core-modules/xhr"],
"xml": ["node_modules/tns-core-modules/xml"]
} |
@sis0k0 what do your recompile times look like with that setup? i was getting 40-50s recompiles (on an absurdly tiny project) until i dropped the path maps, at which point it dropped to ~2s. |
@zackschuster |
|
@zackschuster, similar times. |
If you are still on Angular 6 and using Docker:
This worked for my team's project. We may consider using 4096 or even 2048 if that works for us. |
@jiminikiz You can check how much memory the build process takes to determine how much memory you need to allocate to it. For example, if the process takes at max 3GB RAM, then you can allocate 4GB instead of the 8GB you're allocating now. |
Hi guys, I am working in an app that is being developed with Visual Studio. How can I set --max_old_space_size=8192 and where? I am publishing the project with publish option so I don't know where to set it. Please any help? p.s. If I comment
(and "buildOptimizer": true because it depends on aot) I can publish the project. |
before i face problem with java heap out of memory node --max_old_space_size=8192 'node_modules/@angular/cli/bin/ng' build --prod Else you can set your angular.json and call build-prod in u r command now i am using --prod its more power full other than aot
|
I want to test my prod version with
Where can I add --max_old_space_size=819 because right now Im getting
Really need some help Thx |
Does this not work for you? The --max_old_space_size argument is for node, not ng |
Just want to highlight something I said in #6795 (comment) because it happlies here as well: Increasing the memory limit is not a hack, and something you should expect to do at some point. Node processes have a default memory limit of about 1.7gigs. When a node process starts getting close to the memory limit it needs to spend more and more time doing garbage collection to free up memory, which in turn makes it run more slowly. Bigger projects will use up more memory than smaller projects so at some point a project will hit the memory limit. I personally use a
It's hard to act on many of these reports since there is no objective reproduction that we can follow. It's not that we don't believe that builds can be slow. But builds can be slow for many reasons. It's exceedingly likely that the projects that are seeing the most dramatic build times are suffering from some odd problem somewhere in the pipeline that is not a general problem, and for those we really need to reproduce it to fix it. General performance improvements are of course always helpful, and we try to do them as much as possible. But the absolute best way of getting us to fix issues, especially hard to fix ones, is to offer concrete repros. |
@filipesilva everybody says that we have to use "hack" and solutions, but not where we can put that in an automated publishing file. Can we use that in angular.json and where? this is my angular.json right now:
where can I put that to make it build? Thank you very much. |
@dobrinsky the code sample I showed was an npm script. Those scripts go into the
When you use have that script, you can use |
Thank you very much @filipesilva It still won't work
|
I started seeing this on my Azure DevOps Build server after upgrading to Angular 7. Adding the following to
|
If you have this problem with quagga js library , pay attention that "@angular/service-worker" is installed before "quagga": "^0.12.1" package. |
i could run with optimizejs using |
For people who missed @dakotamurphyucf like I did: |
Or just use |
@marcj this solution worked for me. I set NODE_OPTIONS for windows with following command: Installing increase-memory-limit, did not work for me on windows. I have not tried on linux/ubuntu or other OS. |
@jatinderkumargupta Please note that it's not enough to install |
Thanks @HarelM, I run that like you mentioned, but it did not work for me. May be some other problem then. |
In Azure Devops I added a command line task which executes the command below prior to the ng build: node --max-old-space-size=8192 This seems to have resolved the issue for now.. |
@ImranAhmed thanks for the suggestion. However where abouts do you add it in angular.json? If I add it I get an 'Property build-prod' not allowed? |
Add it to package.json under the 'scripts' section not angular.json. If you are facing the issue with your Azure DevOps build you can then call this new script command that you just added from your AzureDevops build task. |
I tried scripts but got errors. I ended up following the suggestion to export NODE_OPTIONS in OS and it worked. Many thanks |
Hi all, This thread was opened a while ago, and over time new memory problems have arisen and been solved. Meanwhile a lot of reports still appear here as comments. Having all the feedback in a single thread makes it hard to get meaningful reports, or to inform people of what versions the regressions that affect them were fixed. At the time of writing, there are 450 hidden comments: Having so many hidden comments makes it hard for people to find information in anything but the latest comments. But on the other hand I don't think most people would go through all of the comments anyway. New users that see this thread mostly read the first and latest comments and lose things said in between. So for the reasons stated above (high volume of comments, hidden comments, hard to report and inform people) I'm also locking this issue to prevent this comment from being lost as new comments come in. Thank you to everyone that reported and helped diagnose these memory problems. If you encounter any new ones, please open a new issue so we can give that specific regression our full attention and provide a resolution for it. So I'd like to leave the last comment in this thread as reiterating what I said in #5618 (comment), as I think that is what will help most people that find this issue: Increasing the memory limit is not a hack, and something you should expect to do at some point. Node processes have a default memory limit of about 1.7gigs. When a node process starts getting close to the memory limit it needs to spend more and more time doing garbage collection to free up memory, which in turn makes it run more slowly. Bigger projects will use up more memory than smaller projects so at some point a project will hit the memory limit. I personally use a npm script for this:
npm scripts scripts go into the
When you use have that script, you can use |
Bug Report or Feature Request (mark with an
x
)Versions.
Repro steps.
ng build --prod --aot
The log given by the failure.
Desired functionality.
I would like to be able the app using AOT.
Mention any other details that might be useful.
I have tried changing
ng.cmd
to this:and
ngc.cmd
to:I have 8GB swap file. The build fails after 20-25 minutes standing on 92% progress.
The text was updated successfully, but these errors were encountered: