You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AOT build fails due to "JavaScript heap out of memory" #5618
Thanks for getting me that CPU profile. So most of the time is spent on some array operations. It seems that this is happening as part of webpack module detection. All of the operations that take a long time happen on webpack/lib/optimizer/RemoveParentModulesPlugin.js.
@TheLarkInn does this ring a bell to you? I wonder if it's some kind of circular import problem.
@pleerock what version of webpack comes up when you do npm ls webpack btw?
Le 3 janv. 2018 à 10:58, Umed Khudoiberdiev ***@***.***> a écrit :
We still have this issue. We had this issue since ***@***.*** when I first time used angular CLI. Then I switched to angular starter and everything worked. Now Im trying to use angular cli again on the same project (upgrade from angular 4) and now I still have same issue with angular 5.1 and cli 1.6.2.
We have a really huge project and we are using angular on this project from early versions of angular since 2013.
When I simply use ng build build is going 1 hour. Here is a log.
When I use ng build -prod or ng build -prod -aot I always have an error (after few minutes of build):
ng build -prod -aot
10% building modules 3/3 modules 0 active
<--- Last few GCs --->
[30628:0x102804600] 151498 ms: Mark-sweep 1405.8 (1664.5) -> 1405.8 (1664.5) MB, 1634.9 / 0.0 ms allocation failure GC in old space requested
[30628:0x102804600] 152767 ms: Mark-sweep 1405.8 (1664.5) -> 1405.7 (1616.5) MB, 1268.5 / 0.0 ms last resort
[30628:0x102804600] 154066 ms: Mark-sweep 1405.7 (1616.5) -> 1405.7 (1601.0) MB, 1298.4 / 0.0 ms last resort
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x14c9d8b1cef1 <JSObject>
1: set [native collection.js:~247] [pc=0x2fa4affd9607](this=0x166929284d21 <Map map = 0x20d66a1183b9>,p=0xb60e511a3c9 <NodeObject map = 0x78bae661b01>,x=0x3ce8d86d6ce9 <Object map = 0x3647e82a689>)
3: record ***@***.***/compiler-cli/src/transformers/node_emitter.js:135] [bytecode=0x214b10b7f429 offset=37](this=0x166929284ce9 <_NodeEmitte...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node::Abort() [/usr/local/bin/node]
2: node::FatalException(v8::Isolate*, v8::Local<v8::Value>, v8::Local<v8::Message>) [/usr/local/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const*, bool) [/usr/local/bin/node]
4: v8::internal::Factory::NewFixedArray(int, v8::internal::PretenureFlag) [/usr/local/bin/node]
5: v8::internal::OrderedHashTable<v8::internal::OrderedHashMap, 2>::Rehash(v8::internal::Handle<v8::internal::OrderedHashMap>, int) [/usr/local/bin/node]
6: v8::internal::Runtime_MapGrow(int, v8::internal::Object**, v8::internal::Isolate*) [/usr/local/bin/node]
7: 0x2fa4afe040dd
Abort trap: 6
If you want to know how many code and files we have:
cloc ./src/
2705 text files.
2680 unique files.
https://github.com/AlDanial/cloc v 1.66 T=12.20 s (219.4 files/s, 17125.4 lines/s)
-------------------------------------------------------------------------------
Language files blank comment code
-------------------------------------------------------------------------------
TypeScript 2662 21207 15921 143472
CSS 4 4084 203 18682
SASS 6 772 305 4144
JSON 3 0 0 68
HTML 1 8 5 25
-------------------------------------------------------------------------------
SUM: 2676 26071 16434 166391
-------------------------------------------------------------------------------
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
What version of NodeJs are you running here? If < 8.9, would you mind testing and reprofiling. There is significant work done in V8 with garbage collection that surfaced in that version of node that we collaborated with the V8 team on.
@JaapMosselman the chunk asset optimization in prod builds is when module concatenations and Uglification happen. This are the optimizations that reduce your bundle size by analyzing code and dropping unused one.
It is slow by it's very nature, but #8668 (merged but waiting for 1.7 to be released) will help by running Uglify in parallel.
@pleerock I've been looking at Webpack 4 and thought maybe it could help since there are a lot of performance improvements there. The plugin in question has suffered some changes:
Started getting this issue last month, did try so many workarounds and got it working after upgrading to angular-cli 1.6.2. But the build started taking about 45 minutes, made it difficult to push new builds. But at least it was working. Now getting the issue again, and this time, it only works occasionally. And when it works it still takes about an hour. I am guessing the issue started occurring after the codebase grew above some threshold, before this, the build used to take ~10 mins.
Is there a way to get over the frequent build failures. This is the output I am getting:
92% chunk asset optimization<--- Last few GCs --->
[34132:0000025213C0DB90] 2282774 ms: Mark-sweep 1401.9 (1713.9) -> 1401.9 (1699.9) MB, 1637.6 / 0.0 ms last resort GC in old space requested
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0000037423C25EE1 <JSObject>
2: visit [0000033FF8602311 <undefined>:7667] [bytecode=0000002651BE0769 offset=620](this=0000038789453039 <TreeWalker map = 0000020B4AB1BD21>,node=000001D6E5AAD121 <AST_VarDef map = 000002C8A2BBA649>,descend=0000001D6E073821 <JSFunction (sfi = 000003D9CF111AF9)>)
4: _visit [0000033FF8602311 <undefined>:1512] [bytecode=000003D9CF10CF99 offset=57](this=0000038789453039 <TreeWalker map = ...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
@filipesilva that did the trick. I tried it but I think I mistakenly tried --max-old-space-size instead of --max_old_space_size. It works fine now and only takes ~4 min. And about ~8 min on CI server. Thanks.
I have made some research and according to this both --max-old-space-size and --max_old_space_size syntax are valid. Here is a link in nodel documentation about --max-old-space-size. Also I found some people complain that first approach is not working, but obliviously both should work.
Looks like something got better, build times reduced by 50% in my project + memory consumption as well (for single node process) , although I think I see more node processes being spawned. @clydin : what was fixed?
@pleerock about --max-old-space-size and --max_old_space_size. node 8.9.3 on Windows gives me the following error while using --max-old-space-size
$ npm run start
> test@0.0.0 start C:\Projects\test
> node --max-old-space-size=8192 ./node_modules/.bin/ng serve
C:\Projects\test\node_modules\.bin\ng:2
basedir=$(dirname "$(echo "$0" | sed -e 's,\\,/,g')")
^^^^^^^
SyntaxError: missing ) after argument list
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! test@0.0.0 start: `node --max-old-space-size=8192 ./node_modules/.bin/ng serve`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the test@0.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\sabee\AppData\Roaming\npm-cache\_logs\2018-01-13T04_47_40_099Z-debug.log
Is this supposed to happen or is it an issue with the way I configured it ?
Reacted by Michael, Anatolii Teselko and andyk2600
@filipesilva I was able to build site using webpack4 (with fixes applied by webpack team) + aot using your branch in 40 minutes. But for some reason index.html is not emitted (even with regular dev build)
This started happening for us. How can this happen when I have locked down all my angular versions? Does the CLI not follow the proper versioning? Is there any fix for this?
I tried what @clydin said, using 1.7.0-beta.0 worked like a charm, it did cut my building time from over 30 minutes to 3 minutes.
Thank you angular-cli team.
Reacted by Peter Kisinga
Reacted by radoslavpetranov, Supakorn Thongtra, Willian Oliveira, bertrandg and Peter Kisinga
I did also a test run with 1.7.0-beta.0. The build time dropped from 13 minutes to 6.5 minutes (on my not to fast build machine). On my dev machine it builds now in 3.6 minutes (with 1.6.0 it was 7.8 minutes).
The size of the main bundling increased a little from 2653 to 2664 KB.
I needed to add @angular-devkit/core as a dev dependency to my package, else it would not be installed automatically.
I tried what @clydin said, using 1.7.0-beta.0 worked like a charm, it did cut my building time from over 30 minutes to 3 minutes.
Thank you angular-cli team.
Just give it more memory. It is inevitable that the process consumes more and more memory as the project size grows. There's no way around that. The only thing that (probably) will fix this is https://bazel.build, but that's still quite far in the future.
So, the fix imho is that ng just adds some node flags by default and let's call it a day.
It's not inevitable. It does point to a fundamental flaw in the build architecture. If we default the --max_old_space_size=8192 flag, how large of a project will this build until that value is too small?
I'm just being practical, the build uses heavily webpack, node etc. and a lot of other dependencies that may not be trivial to rewrite. The change to bazel is coming, so how many man years should be put into this old build pipeline?
As long as the memory requirement is not outrageous, I'd like to vote the effort to be put into something else, as there are a lot of things that need attention. It's 2018, so I don't think 4 or 8 gigs of memory is that much.
I also don't think that many users would have noticed that the build uses 4 gigs of memory if that was the default.
I think something is kind of messed up with the SASS processing which might be contributing to these issues (definitely for dev builds but I'm not 100% sure for aot).
Essentially there seems to be something weird happening with sass de-duplication. In my project I had a common sass file with a bunch of includes (bootstrap and stuff). This is liberally included across component scss files with the expectation it would be de-duplicated in the build.
However I realized my dev build was up to 150MB for the main.bundle.js and it was hammering my workstation when it built. By re-structuring the scss to only include was was necessary in each component I bought this down to like 11MB.
For the aot build it was less significant (I think most of the size was from sourcemaps) but still went from:
I tried to track the memory usage as well. It seemed like with the improved scss it maxd out at about 1300MB memory to do the aot build. With the old scss setup it was similar but briefly spiked up to over 2.5GB at the end of the process. So it could be that memory useage is also affected by the duplicated scss.
(I'm using cli v1.7.0-beta.0 btw. rc.0 breaks my fonts in aot).
edit: slightly more scientific readout of memory usage:
Inefficent scss includes:
More efficent scss:
Not much in it really.
also improved scss with cli v1.7.0-rc.0 instead of beta.0:
I've installed increase-memory-limit and after I run it, although it ran successfully and it changed the files in the local project folder (I checked the files), the ram usage was still somewhere 1400 mega bytes and not more.
What I did after that is. I went to the folder where npm is installed which in my case was
C:\Users\USER\AppData\Roaming\npm
and I opened ng.cmd and edited it and added --max-old-space-size=10240 in both places (in the if and else clause)
Only after I did that and tried ng build --prod it started to use more ram.
Here in the photo you can see that I'm running two command prompts. The first one is after I ran increase-memory-limit, and the second one is after I edited the ng.cmd file manually. You can see that it started to use 3000 mega bytes.
Before doing this edit, the rare times that it worked (to build the project) it took me 660s and now it did it for 295s.
I hope it will help you.
Reacted by Kanji Keraliya, akrivchenko-silent, Itiel Ishon, Joey Goertzen, renepape, Arij Ben Othman, iotas, Alex Wiese, Angel Jasso, Andi Pätzold and 2 more
@FOSSKolkata
But I'm getting the warning of > @angular/compiler-cli@5.2.5 requires a peer of typescript@>=2.4.2 <2.7 but none is installed. You must install peer dependencies yourself.
my project compiles on local machines but not in the CI due out of memory errors (8gb ram , 2gb swap).
setting max-old-space-size is not a viable option for our CI pipelines.
solved updating typescript to 2.7.x but a nasty warning about 'ng compiler not supporting that version of typescript' shows up.
this is an issue for us too;
we are using a hosted VSTS build environment;
node: v 8.x
npm: 5.6.0
@angular/cli: 1.7.2
I tried running npm install -g increase-memory-limit && increase-memory-limit prior to running the build command (node ./node_modules/@angular/cli/bin/ng build --prod --e=beta --sourcemaps=true), but it did not help. I still get OOM error as indicated above.
EDIT: updating the build command to the following, seems to have 'fixed' the issue. node --max_old_space_size=10240 ./node_modules/@angular/cli/bin/ng build --prod --e=beta --sourcemaps=true
Facing the same issue.. Tried increasing the memory allocation which resolved this for a while, but after couple of days, things have started to fail again continuously.
Increasing the memory limit might just be a patch and never resolve what is causing this. Any idea?
@roymj88 Largely the performance issues have stemmed from build optimizations introduced in webpack that were incredibly expensive in terms of RAM usage for build. At least two of these issues were found and resolved in webpack itself, in part through the help of members of the angular-cli team.
So think it's really important to state what version you're using, as it may have been fixed for you, and roughly how large your project is. As depending on your size you will hit that wall eventually. Where the total build time and I think RAM usage does scale at least linearly with number of files.
So a quick-fix is indeed to simply increase the RAM usage even further. Alternatives to that:
Isolate the issue into a public repository or simply share your code if that is possible. Will help them a lot in trying to triage the issue.
Turn off build-optimizer (it's on by default for production). If you're not concerned about payload size of your app turning this flag off will likely speed up your production build significantly.
Upgrade to Angular 6 beta and angular-cli 6 beta. The latest version uses Webpack 4 along with some other optimizations that supposedly should make builds faster.
it seems that they dont care about this.
@Aindigo I think that's incorrect. There are steady performance improvements both in the cli and more importantly in Webpack, which the angular-cli sometimes contribute themselves. Bazel as an alternative to Webpack will very likely become a very much more performant alternative while version 6 does seem to come with a fair share of improvements to the build speed in general.
You could argue for different prioritization, with the big drawback of delaying other improvements and features like Service Workers and schematics.
Regardless, think the team is doing an awesome job and hope to continue see improvements in version 6 and onwards.
Reacted by jaa1982, Yazeed Sabri, Shai Reznik and bertrandg
@DenisVuyka Are you sure the above issue is resolved with the latest version i.e 1.7.0? Upgrading to the latest version may have dependency issues and upgrading instantly may not be a choice that we can do right-away.
@roymj88 might require increasing the RAM to 4 or 8, maybe rely on swap if you don't have enough RAM. What is reasonable RAM usage partly depends on the size of your project. Supply the approximate size of your project. How many thousand lines of code?
However agree with @DenisVuyka . If you want any optimizations you will have to upgrade to the latest version of angular-cli. Which should likely include upgrading to Angular 5 and node 8.x. If you're not using angular universal/ssr, service-workers or specific libraries tied to older versions it shouldn't be too much effort.
If you're not using it, you should also use yarn or npm lock files if you want to avoid dependencies unexpectedly breaking under you.
In my experience leaving the --sourcemaps flag out fixes this issue during AOT compilation of larger projects and honestly what do we even need sourcemaps for in production.
@Flexicon Thanks for the tip. We like to include --sourcemaps on our beta/test environment, but build with the --prod flag so the bits are the same as in production environment. I agree, no need for sourcemaps in production.
we were able to sort this out upgrading angular-cli in the package.json file to 1.6.7, and leaving typescript on 2.3.4 so the compiler does not warn about un-supported versions
gulp handles node flags already. ng could do the same, with the help of https://www.npmjs.com/package/flagged-respawn. This module respawns the node process if v8 flags are present.
Until then the workaround for both Linux & Windows machines is running ng as node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng build ...
Reacted by andrea-spotsoftware, Luiz Gomes, Josip Bojčić and Brad Johnson
@ar53n - I have circular dependencies defined in my application amongst my models, but those give a warning at compile time, since they will only give an error at run time and you actually create your models with the circular dependencies implemented (which shouldn't be the case).
I got my AOT build working with the solution provided by @awerlang:
How are people still having issues with this? Using the 1.7.2 build of @angular/cli works perfectly without changing the memory flag. This is on both a computer with an old i3 and 8gb ram as well as an amd fx6350 with 32gb ram.
@jarodsmk then explain how the very low spec i3/8gb ram computer works fine on 1.7.2? its evidently a lot lower spec than your machine and has only half the ram but works fine? Based on the fact that some people need the flag and some dont, i suspect its more of a computer issue than cli issue
Just a reminder that the memory consumption grows the more typescript / html files it has to analyze. At some point your project will grow over the limit and you need the flag. It's not about the machine.
The cli has been optimized, so the newer ones can cope more files, but still in the end it will run out off memory on larger projects.
Memory consumption is (mainly) determined by two factors - the cli version and the size & complexity of your project.
Actually I could get both of my big projects to compile with ng build --prod --base-href ./ --aot if I add --sm then both build fail. This is with latest angular cli (both global and project) and latest typescript (both global and project).
@jarodsmk so do i, its currently at around 20 modules, 3 normal components
(to use with the html selector), around 10 service files and around 15
interfaces, it builds fine on the i3/8gb ram build without the memory flag.
I would say that its very complex
@makdeniss - Yea, adding the source map parameter is a common issue because the memory requirements when generating them on larger projects can be enormous.
But on a debug/qa build, adding source maps could be beneficial
I have 8 modules with approximately 89 components, 20 services, a number of interfaces and I believe around 52 model classes, failing with or without sourcemaps
@jarodsmk both of my projects are bigger and removing that --sm and also upgrading to the latest deps for ts and cli (and of course ng) solved the js memory error.
Hmm, we're having 60 components, 5 own modules, 47 3rd party modules imported and about 50 services. I consider this to be a really simple app compared to some of the enterprise stuff I've worked with.
I ran into a this issue today, but I saw it when attempting to perform a regular ng build. It would stop at 10% and hang until the error occurred. Allocating more memory did allow it to build. I found this issue on typescript (microsoft/TypeScript#14628) and one of the comments led me to changing the tsconfig.app.json.
tsconfig.app.json
"include": [
"src",
"typedefs"
],
This appears to have fixed the issue. However, the tests will still not work and I have not been able to add anything to the tsconfig.spec.json to get them working.
I've been following this thread for a while, but not sure if this has been mentioned before.
In my case, I'm doing the auto-rebuild stuff. So when I make a modification in my source, it'll rebuild and reload the browser page. The initial startup build always works, but after doing approximately 20 or more modifications and therefore rebuilds, I end up getting the out of memory error.
I have a fairly small project so it isn't the issue that the project itself will build and hit a memory limit. I ran into the memory issue after 10 or more repeated builds were run in TeamCity. Restarting the build agent/server got things back to normal, so it seems that memory is not being cleared after each build and eventually aggregating toward the limit.
@Ericdowney angular-cli 1.3.1 is quite old in this context. A lot has happened since then until 1.7.x. And a lot more is about to happen when they release 6.x. Might want to either switch to 1.7.x now and then use ng update to update to 6.x when that comes out and you also want to migrate to Angular 6.
I wouldn't expect any fixes or help with angular cli version 1.3.1. Maybe version 6 will have similar LTS support but would always assume the latest version to give the best experience.
I previously had this error on Angular 5 with --aot flag and then it went away with the updates to @angular/cli. I have now upgraded to Angular 6 and the issue is back :/. I'm using:
Thank you @Koslun for this complete example. I went with the 1st approach and works well! I'm curious as to why this isn't mentioned anywhere in docs. This seems like any reasonably sized project would have to do anyway.
@Enngage think it's cause the goal is that this is never really supposed to happen. Where having to use this can often also instead be the result of some regression in angular-cli, Webpack or even Node, such as this fixed but unreleased regression in Node: nodejs/node#19769.
Given that this issue itself has the tag FAQ and the traffic it's garnered I agree that it might be worthwhile to add it to some FAQ in the documentation.
Have the same issue and sudo node --max-old-space-size=4096 /usr/local/bin/ionic cordova build android --prod didn't help. I'm using MacOs. Any advice ?
I am following this way: Inspect the bundles and I have the same error: "devDependencies": { "@angular/cli": "^1.7.2", "@angular/compiler-cli": "^5.2.9",
ng build --prod --sourcemaps
92% chunk asset optimization
<--- Last few GCs --->
[6360:0000000000398AE0] 1741315 ms: Mark-sweep 1399.2 (1647.1) -> 1398.3 (1648.6) MB, 1257.4 / 0.0 ms allocation failure GC in old space requested
[6360:0000000000398AE0] 1742847 ms: Mark-sweep 1398.3 (1648.6) -> 1398.1 (1603.1) MB, 1530.9 / 0.0 ms last resort GC in old space requested
[6360:0000000000398AE0] 1744175 ms: Mark-sweep 1398.1 (1603.1) -> 1398.1 (1595.1) MB, 1328.2 / 0.0 ms last resort GC in old space requested
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0000018821D25EE1
1: exec(this=00000156D3AF9AA9 <JSRegExp <String[53]: /** PURE_IMPORTS_START (\S+) PURE_IMPORTS_END */>>,000003A248D4D541 <Very long string[6384078]>)
3: getMatches(aka getMatches) [C:\Users\Utente\Desktop\Workspace\rebus5\node_modules@angular-devkit\build-optimizer\src\purify\purify.js:48] [bytecode=000003F790876209 offset=16](this=000000FCE1C02311 ,str=000003A248D4D54...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
1: node_module_register
2: v8::internal::FatalProcessOutOfMemory
3: v8::internal::FatalProcessOutOfMemory
4: v8::internal::Factory::NewRawTwoByteString
5: v8::internal::Smi::SmiPrint
6: v8::internal::AllocationSpaceName
7: v8::internal::RegExpImpl::Exec
8: v8::internal::RegExpImpl::Exec
9: v8::internal::ParserBasev8::internal::Parser::MarkLoopVariableAsAssigned
10: 00000231754047A1
@Marudhuraj Other than turning off build-optimizer, turning off source maps can also help. Would otherwise also in general recommend updating to latest angular-cli to get the best performance as well as ensure you're on Node version 8.11.2 or higher as there's a performance regression affecting Webpack builds of some versions below that in the 8.x series.
@joshuwhi@Koslun My personal experience was I was encountering this issue after 5 or more builds of the same app in succession on a team city agent. I have an opportunity to set up my CI on the latest Node, NPM, and Angular and will find some time in the next week or so to set up just the boilerplate ng new app building periodically throughout the day to see if the suggested dev environment versions mentioned here actually no longer reproduce the issue.
@Marudhuraj
I solved this issue by doing the following step:
I used the command "npm run build" which internally uses "ng build"
I update my "ng.cmd" file at following location "\UI\node_modules.bin" (UI being the project folder) by this code
================= @if EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" --max_old_space_size=8192 "%~dp0..@angular\cli\bin\ng" %*
) ELSE ( @SETLOCAL @set PATHEXT=%PATHEXT:;.JS;=;%
node --max_old_space_size=8192 "%~dp0..@angular\cli\bin\ng" %*
)
================
this is basically adding more memory for node to execute
3. Update the package.json file, by doing following steps:
replace
"build": "ng build",
by this:
"build": "ng build --prod --build-optimizer",
Hi @aryavijay ,
Now i'm getting this error, how to resolve the app module factory error
ERROR in ./src/app/app.module.ngfactory.js
Module not found: Error: Can't resolve 'ngx-store/dist/src/service/local-storage.service' in 'C:\Users\a811891\taskmanagementv2ui\src\app' resolve 'ngx-store/dist/src/service/local-storage.service' in 'C:\Users\a811891\taskmanagementv2ui\src\app' Parsed request is a module using description file: C:\Users\a811891\taskmanagementv2ui\package.json (relative path: ./src/app) Field 'browser' doesn't contain a valid alias configuration after using description file: C:\Users\a811891\taskmanagementv2ui\package.json (relative path: ./src/app) resolve as module C:\Users\a811891\taskmanagementv2ui\src\app\node_modules doesn't exist or is not a directory C:\Users\a811891\taskmanagementv2ui\src\node_modules doesn't exist or is not a directory C:\Users\a811891\node_modules doesn't exist or is not a directory C:\Users\node_modules doesn't exist or is not a directory C:\node_modules doesn't exist or is not a directory looking for modules in C:\Users\a811891\taskmanagementv2ui\node_modules using description file: C:\Users\a811891\taskmanagementv2ui\package.json (relative path: ./node_modules) Field 'browser' doesn't contain a valid alias configuration after using description file: C:\Users\a811891\taskmanagementv2ui\package.json (relative path: ./node_modules) using description file: C:\Users\a811891\taskmanagementv2ui\node_modules\ngx-store\package.json (relative path: ./dist/src/service/local-storage.service) no extension Field 'browser' doesn't contain a valid alias configuration C:\Users\a811891\taskmanagementv2ui\node_modules\ngx-store\dist\src\service\local-storage.service doesn't exist .ts
@aryavijay I feel like setting max_old_space_size in various places is not really a solution, but rather a workaround.
This was not an issue before I upgraded the project and cli to angular 6.
Reacted by Netanel Draiman, Willian Oliveira, Austin Turner, frankiDotNet and Dirk Luijk
For anyone experiencing "JavaScript heap out of memory" when running a build:
I just upgraded to Angular 6 from 5 today and started getting these when building my universal server. I was on @nagular-devkit/angular-build: 0.8.0-rc8 and it kept failing. Downgrading to 0.6.3 worked as per: #5618 (comment)
before i face problem with java heap out of memory
and i run code with increasing memory but i failed with module error..
and i upgraded to angular 6 and successfully build with --prod mode
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 npm script for this:
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.
Reacted by Rory Fuhrer, Paul Draper, Jan Papenbrock and Eduard Deza
When you use have that script, you can use npm run ng-high-memory -- followed by the arguments instead of ng inside that project. Always use the double dash before arguments, otherwise they might not be parsed correctly.
Reacted by Judah Gabriel Himango, Sean G. Wright and Sujit Patil
Reacted by Teoman Tuncer, felikf, Eddie Oosthuizen, LosD, Lucas H., Ennio Bozzetti, Nikola Andreev, Mario Mol, Sean G. Wright, Jan Papenbrock and 3 more
i could run with optimizejs using node --max-old-space-size=8192 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build --release --prod --minifyjs --minifycss --optimizejs
For people who missed @dakotamurphyucf like I did:
using increase-memory-limit package after running npm install will reduce all need to know where binary files are and will do it for all the files - which in my case is very useful since I'm running both regular build and cordova build.
I'm using it only in my CI build script since locally it runs well.
basically: npm install increase-memory-limit -g
And run the command increase-memory-limit.
Pain is gone! No more suffering (for me at least)...
@jatinderkumargupta Please note that it's not enough to install increase-memory-limit, you need to run it also after npm installation of all packages has completed. I'm using windows and it worked for me.
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.
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:
When you use have that script, you can use npm run ng-high-memory -- followed by the arguments instead of ng inside that project. Always use the double dash before arguments, otherwise they might not be parsed correctly.
Activity
filipesilva commentedon Jan 3, 2018
Thanks for getting me that CPU profile. So most of the time is spent on some array operations. It seems that this is happening as part of webpack module detection. All of the operations that take a long time happen on
webpack/lib/optimizer/RemoveParentModulesPlugin.js.@TheLarkInn does this ring a bell to you? I wonder if it's some kind of circular import problem.
@pleerock what version of webpack comes up when you do
npm ls webpackbtw?pleerock commentedon Jan 3, 2018
aminebizid commentedon Jan 3, 2018
TheLarkInn commentedon Jan 4, 2018
What version of NodeJs are you running here? If < 8.9, would you mind testing and reprofiling. There is significant work done in V8 with garbage collection that surfaced in that version of node that we collaborated with the V8 team on.
pleerock commentedon Jan 5, 2018
@TheLarkInn updated from
v8.4.0tov9.3.0.Profiled first 12 minutes of
RemoveParentModulesPluginexecution:CPU-20180105T160658.cpuprofile.zip
filipesilva commentedon Jan 5, 2018
@JaapMosselman the
chunk asset optimizationin prod builds is when module concatenations and Uglification happen. This are the optimizations that reduce your bundle size by analyzing code and dropping unused one.It is slow by it's very nature, but #8668 (merged but waiting for 1.7 to be released) will help by running Uglify in parallel.
@pleerock I've been looking at Webpack 4 and thought maybe it could help since there are a lot of performance improvements there. The plugin in question has suffered some changes:
webpack@3.10.0: https://github.com/webpack/webpack/blob/b545b519b2024e3f8be3041385bd326bf5d24449/lib/optimize/RemoveParentModulesPlugin.jswebpack@4.0.0-alpha.3: https://github.com/webpack/webpack/blob/9334fd8547831ded7f11e05319616a72ea0b4698/lib/optimize/RemoveParentModulesPlugin.jsIt looks like there's a fair bit of optimizations changes there. But I'm not sure if the bottleneck has changed.
There's two places where time is being spent on your CPU profile:
hascall inside thehasModulefunction:filtercall inside thehasModulefunction:This function hasn't changed though so I don't think it would speed up your case. I'm going to open an issue in webpack about this.
EDIT: opened as webpack/webpack#6248
sabeersulaiman commentedon Jan 8, 2018
Started getting this issue last month, did try so many workarounds and got it working after upgrading to angular-cli 1.6.2. But the build started taking about 45 minutes, made it difficult to push new builds. But at least it was working. Now getting the issue again, and this time, it only works occasionally. And when it works it still takes about an hour. I am guessing the issue started occurring after the codebase grew above some threshold, before this, the build used to take ~10 mins.
Is there a way to get over the frequent build failures. This is the output I am getting:
Angular Version: 4.2.4
Angular-cli Version: 1.6.2
TypeScript Version: 2.3.4
Node Version: 8.9.3
npm Version: 5.5.1
This are the number of individual files:
Any guidance will be much appreciated. Stuck at this no build situation for the last 24 hours 😕
filipesilva commentedon Jan 8, 2018
@sabeersulaiman have you tried setting a npm script for increasing the memory available? I mentioned it in #5618 (comment).
If you still have very long builds (10+ minutes) and have a repro available, I'd love to look into it.
sabeersulaiman commentedon Jan 9, 2018
@filipesilva that did the trick. I tried it but I think I mistakenly tried
--max-old-space-sizeinstead of--max_old_space_size. It works fine now and only takes ~4 min. And about ~8 min on CI server. Thanks.pleerock commentedon Jan 12, 2018
I have made some research and according to this both
--max-old-space-sizeand--max_old_space_sizesyntax are valid. Here is a link in nodel documentation about --max-old-space-size. Also I found some people complain that first approach is not working, but obliviously both should work.pleerock commentedon Jan 12, 2018
@filipesilva Im able to do
buildusing webpack3, latest angularcli and it takes 1 hour with node 8 as we discussed.Now, Im trying to build production version using
build --prodand having a memory error on 92%:clydin commentedon Jan 12, 2018
If you have the time, can you try with CLI 1.7.0-beta.0?
dragonflypl commentedon Jan 12, 2018
Looks like something got better, build times reduced by 50% in my project + memory consumption as well (for single node process) , although I think I see more node processes being spawned. @clydin : what was fixed?
sabeersulaiman commentedon Jan 13, 2018
@pleerock about
--max-old-space-sizeand--max_old_space_size. node 8.9.3 on Windows gives me the following error while using--max-old-space-sizeIs this supposed to happen or is it an issue with the way I configured it ?
pleerock commentedon Jan 13, 2018
@filipesilva I was able to build site using webpack4 (with fixes applied by webpack team) + aot using your branch in 40 minutes. But for some reason
index.htmlis not emitted (even with regular dev build)rainstormza commentedon Jan 16, 2018
This error happen with cli 1.6.2
use this command works for me
Sarfarazsajjad commentedon Jan 18, 2018
updated to @angular/cli@1.6.4
but still the same error 'FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory'
rafiwardak2003 commentedon Jan 19, 2018
This started happening for us. How can this happen when I have locked down all my angular versions? Does the CLI not follow the proper versioning? Is there any fix for this?
Satyadatla commentedon Jan 19, 2018
@Sarfarazsajjad and @sabeersulaiman are you trying with 64 bit node or 32 bit node?
64 bit node with --max_old_space_size should build fine for large applications in --prod mode.
nadhir-falta commentedon Jan 19, 2018
I tried what @clydin said, using 1.7.0-beta.0 worked like a charm, it did cut my building time from over 30 minutes to 3 minutes.
Thank you angular-cli team.
JaapMosselman commentedon Jan 23, 2018
I did also a test run with 1.7.0-beta.0. The build time dropped from 13 minutes to 6.5 minutes (on my not to fast build machine). On my dev machine it builds now in 3.6 minutes (with 1.6.0 it was 7.8 minutes).
The size of the main bundling increased a little from 2653 to 2664 KB.
I needed to add @angular-devkit/core as a dev dependency to my package, else it would not be installed automatically.
mcherb commentedon Feb 7, 2018
i had to move from angular-cli 1.5.0 to 1.6.7 to resolve my build memory bug (without setting --max_old_space_size)
smiera commentedon Feb 12, 2018
For me, 1.7.0-beta.3 not work. Still get:
kanji-keraliya commentedon Feb 15, 2018
update global and local Angular Cli to 1.7.0-rc.0 work for me
update global Angular Cli
update local Angular Cli
npm install @angular/cli@1.7.0-rc.0warmans commentedon Feb 15, 2018
I'd be careful with rc.0 - it corrupts some assets in aot builds e.g. fonts. I think it's been fixed but there hasn't been a release yet.
PsyGik commentedon Feb 15, 2018
Using
@angular/cli@1.7.0-rc.0DID NOT fix the issue.Workaround:
"ng-high-mem": "node --max_old_space_size=8192 ./node_modules/@angular/cli/bin/ng",as mentioned had to be used.This is something which needs to be fixed guys.
swftvsn commentedon Feb 15, 2018
Just give it more memory. It is inevitable that the process consumes more and more memory as the project size grows. There's no way around that. The only thing that (probably) will fix this is https://bazel.build, but that's still quite far in the future.
So, the fix imho is that ng just adds some node flags by default and let's call it a day.
kdubious commentedon Feb 15, 2018
It's not inevitable. It does point to a fundamental flaw in the build architecture. If we default the
--max_old_space_size=8192flag, how large of a project will this build until that value is too small?swftvsn commentedon Feb 15, 2018
I'm just being practical, the build uses heavily webpack, node etc. and a lot of other dependencies that may not be trivial to rewrite. The change to bazel is coming, so how many man years should be put into this old build pipeline?
As long as the memory requirement is not outrageous, I'd like to vote the effort to be put into something else, as there are a lot of things that need attention. It's 2018, so I don't think 4 or 8 gigs of memory is that much.
I also don't think that many users would have noticed that the build uses 4 gigs of memory if that was the default.
That said, I'll shut up now ;)
warmans commentedon Feb 15, 2018
I think something is kind of messed up with the SASS processing which might be contributing to these issues (definitely for dev builds but I'm not 100% sure for aot).
Essentially there seems to be something weird happening with sass de-duplication. In my project I had a common sass file with a bunch of includes (bootstrap and stuff). This is liberally included across component scss files with the expectation it would be de-duplicated in the build.
However I realized my dev build was up to 150MB for the main.bundle.js and it was hammering my workstation when it built. By re-structuring the scss to only include was was necessary in each component I bought this down to like 11MB.
For the aot build it was less significant (I think most of the size was from sourcemaps) but still went from:
to
I tried to track the memory usage as well. It seemed like with the improved scss it maxd out at about 1300MB memory to do the aot build. With the old scss setup it was similar but briefly spiked up to over 2.5GB at the end of the process. So it could be that memory useage is also affected by the duplicated scss.
(I'm using cli v1.7.0-beta.0 btw. rc.0 breaks my fonts in aot).
edit: slightly more scientific readout of memory usage:
Inefficent scss includes:

More efficent scss:

Not much in it really.
also improved scss with cli v1.7.0-rc.0 instead of beta.0:
and v1.6.8:
ZgjimDida commentedon Feb 15, 2018
I've installed increase-memory-limit and after I run it, although it ran successfully and it changed the files in the local project folder (I checked the files), the ram usage was still somewhere 1400 mega bytes and not more.
What I did after that is. I went to the folder where npm is installed which in my case was
C:\Users\USER\AppData\Roaming\npm
and I opened ng.cmd and edited it and added --max-old-space-size=10240 in both places (in the if and else clause)
Only after I did that and tried ng build --prod it started to use more ram.
Here in the photo you can see that I'm running two command prompts. The first one is after I ran increase-memory-limit, and the second one is after I edited the ng.cmd file manually. You can see that it started to use 3000 mega bytes.
Before doing this edit, the rare times that it worked (to build the project) it took me 660s and now it did it for 295s.
I hope it will help you.
kanji-keraliya commentedon Feb 16, 2018
@ZgjimDida its working for me for @angular/cli@1.6.8 after added --max-old-space-size=10240 in both places
FOSSKolkata commentedon Feb 16, 2018
Updating typescript version in package.json to the latest 2.4.x to 2.7.x, fixed the issue for me
vasanthm-bx commentedon Feb 16, 2018
Adding SWAP will help in solving this error?
ZgjimDida commentedon Feb 16, 2018
@kanji-keraliya I'm glad I could help.
jobnte commentedon Feb 21, 2018
@FOSSKolkata
But I'm getting the warning of > @angular/compiler-cli@5.2.5 requires a peer of typescript@>=2.4.2 <2.7 but none is installed. You must install peer dependencies yourself.
pavildon commentedon Mar 6, 2018
my project compiles on local machines but not in the CI due out of memory errors (8gb ram , 2gb swap).
setting max-old-space-size is not a viable option for our CI pipelines.
solved updating typescript to 2.7.x but a nasty warning about 'ng compiler not supporting that version of typescript' shows up.
joshvito commentedon Mar 7, 2018
this is an issue for us too;
we are using a hosted VSTS build environment;
node: v 8.x
npm: 5.6.0
@angular/cli: 1.7.2
I tried running
npm install -g increase-memory-limit && increase-memory-limitprior to running the build command (node ./node_modules/@angular/cli/bin/ng build --prod --e=beta --sourcemaps=true), but it did not help. I still get OOM error as indicated above.roymj88 commentedon Mar 12, 2018
Facing the same issue.. Tried increasing the memory allocation which resolved this for a while, but after couple of days, things have started to fail again continuously.
Increasing the memory limit might just be a patch and never resolve what is causing this. Any idea?
pavildon commentedon Mar 12, 2018
it seems that they dont care about this.
Koslun commentedon Mar 13, 2018
@roymj88 Largely the performance issues have stemmed from build optimizations introduced in webpack that were incredibly expensive in terms of RAM usage for build. At least two of these issues were found and resolved in webpack itself, in part through the help of members of the angular-cli team.
So think it's really important to state what version you're using, as it may have been fixed for you, and roughly how large your project is. As depending on your size you will hit that wall eventually. Where the total build time and I think RAM usage does scale at least linearly with number of files.
So a quick-fix is indeed to simply increase the RAM usage even further. Alternatives to that:
@Aindigo I think that's incorrect. There are steady performance improvements both in the cli and more importantly in Webpack, which the angular-cli sometimes contribute themselves. Bazel as an alternative to Webpack will very likely become a very much more performant alternative while version 6 does seem to come with a fair share of improvements to the build speed in general.
You could argue for different prioritization, with the big drawback of delaying other improvements and features like Service Workers and schematics.
Regardless, think the team is doing an awesome job and hope to continue see improvements in version 6 and onwards.
roymj88 commentedon Mar 16, 2018
@Koslun
The versions are as follows:
The memory limit has been stretched to a whopping 2GB(2097152) and the builds are still failing with the heap memory issue after 92%.
BTW, why is this closed?
Regards
Roy
DenysVuika commentedon Mar 16, 2018
@roymj88 try the latest version. You got 1.2.4 while it's 1.7.3 out there with the improvements discussed in the thread above.
roymj88 commentedon Mar 16, 2018
@DenisVuyka Are you sure the above issue is resolved with the latest version i.e 1.7.0? Upgrading to the latest version may have dependency issues and upgrading instantly may not be a choice that we can do right-away.
Koslun commentedon Mar 16, 2018
@roymj88 might require increasing the RAM to 4 or 8, maybe rely on swap if you don't have enough RAM. What is reasonable RAM usage partly depends on the size of your project. Supply the approximate size of your project. How many thousand lines of code?
However agree with @DenisVuyka . If you want any optimizations you will have to upgrade to the latest version of angular-cli. Which should likely include upgrading to Angular 5 and node 8.x. If you're not using angular universal/ssr, service-workers or specific libraries tied to older versions it shouldn't be too much effort.
If you're not using it, you should also use
yarnor npm lock files if you want to avoid dependencies unexpectedly breaking under you.Flexicon commentedon Mar 22, 2018
In my experience leaving the
--sourcemapsflag out fixes this issue during AOT compilation of larger projects and honestly what do we even need sourcemaps for in production.joshvito commentedon Mar 22, 2018
@Flexicon Thanks for the tip. We like to include
--sourcemapson our beta/test environment, but build with the--prodflag so the bits are the same as in production environment. I agree, no need for sourcemaps in production.pavildon commentedon Mar 26, 2018
we were able to sort this out upgrading angular-cli in the package.json file to 1.6.7, and leaving typescript on 2.3.4 so the compiler does not warn about un-supported versions
makdeniss commentedon Mar 27, 2018
This issue is still present even when upgrading CLI and TS to latest versions. Come on guys...
awerlang commentedon Mar 28, 2018
Regarding increasing available memory:
gulphandles node flags already.ngcould do the same, with the help of https://www.npmjs.com/package/flagged-respawn. This module respawns the node process if v8 flags are present.Until then the workaround for both Linux & Windows machines is running
ngasnode --max_old_space_size=4096 node_modules/@angular/cli/bin/ng build ...jarodsmk commentedon Apr 10, 2018
bump.
ar53n commentedon Apr 11, 2018
Angular 5 and Node 8.9.1, but I have the circular dependency in-app maybe problem there are?
jarodsmk commentedon Apr 11, 2018
@ar53n - I have circular dependencies defined in my application amongst my models, but those give a warning at compile time, since they will only give an error at run time and you actually create your models with the circular dependencies implemented (which shouldn't be the case).
I got my AOT build working with the solution provided by @awerlang:
node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng build ...My exact build command based on my preferences:
node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng b -op aot -sm -v -aotMy versions:
Angular CLI: 1.7.2Node: 6.9.5Angular: 5.2.7mast3rd3mon commentedon Apr 11, 2018
How are people still having issues with this? Using the 1.7.2 build of
@angular/cliworks perfectly without changing the memory flag. This is on both a computer with an old i3 and 8gb ram as well as an amd fx6350 with 32gb ram.jarodsmk commentedon Apr 11, 2018
@mast3rd3mon - well from my comments above, you can see I'm using the same angular-cli version, thus ruling that out.
I'm running an i7 4810MQ w/ 16GB ram, which is irrelevant since if I modify the memory flags I can get an AOT build working
mast3rd3mon commentedon Apr 11, 2018
@jarodsmk then explain how the very low spec i3/8gb ram computer works fine on 1.7.2? its evidently a lot lower spec than your machine and has only half the ram but works fine? Based on the fact that some people need the flag and some dont, i suspect its more of a computer issue than cli issue
Flood commentedon Apr 11, 2018
@mast3rd3mon It depends on how big your project is.
swftvsn commentedon Apr 11, 2018
Just a reminder that the memory consumption grows the more typescript / html files it has to analyze. At some point your project will grow over the limit and you need the flag. It's not about the machine.
The cli has been optimized, so the newer ones can cope more files, but still in the end it will run out off memory on larger projects.
Memory consumption is (mainly) determined by two factors - the cli version and the size & complexity of your project.
jarodsmk commentedon Apr 11, 2018
@mast3rd3mon , regarding what @swftvsn mentioned:
I have a rather complex enterprise-level project I'm working on, with many components and modules.
makdeniss commentedon Apr 11, 2018
Actually I could get both of my big projects to compile with
ng build --prod --base-href ./ --aotif I add--smthen both build fail. This is with latest angular cli (both global and project) and latest typescript (both global and project).mast3rd3mon commentedon Apr 11, 2018
jarodsmk commentedon Apr 11, 2018
@makdeniss - Yea, adding the source map parameter is a common issue because the memory requirements when generating them on larger projects can be enormous.
But on a debug/qa build, adding source maps could be beneficial
jarodsmk commentedon Apr 11, 2018
@mast3rd3mon
I have 8 modules with approximately 89 components, 20 services, a number of interfaces and I believe around 52 model classes, failing with or without sourcemaps
makdeniss commentedon Apr 11, 2018
@jarodsmk both of my projects are bigger and removing that --sm and also upgrading to the latest deps for ts and cli (and of course ng) solved the js memory error.
swftvsn commentedon Apr 11, 2018
Hmm, we're having 60 components, 5 own modules, 47 3rd party modules imported and about 50 services. I consider this to be a really simple app compared to some of the enterprise stuff I've worked with.
What does the --sm flag do @makdeniss ?
makdeniss commentedon Apr 11, 2018
@swftvsn source maps. better debugging posibilities, but for prod this is not needed anyways.
jarodsmk commentedon Apr 11, 2018
@makdeniss hmm interesting, I've tried updating my ts & cli (local on a different branch and global) but didn't change anything
makdeniss commentedon Apr 11, 2018
@jarodsmk how are you building the project? I didn't change any npm memory flags btw. All is as default.
jarodsmk commentedon Apr 11, 2018
@makdeniss
So these fail:
ng b -op aot -aot -sm -vng b -op aot -aot -vBut I resorted to:
node --max_old_space_size=4096 node_modules/@angular/cli/bin/ng b -op aot -aot -sm -vWhich worked. Interesting that setting the max_old_space_size to 4gb helped
makdeniss commentedon Apr 11, 2018
@jarodsmk it should help, because you are giving in more memory. This is a workaround, but a hacky one.
Ericdowney commentedon Apr 17, 2018
I ran into a this issue today, but I saw it when attempting to perform a regular
ng build. It would stop at 10% and hang until the error occurred. Allocating more memory did allow it to build. I found this issue on typescript (microsoft/TypeScript#14628) and one of the comments led me to changing the tsconfig.app.json.tsconfig.app.json
This appears to have fixed the issue. However, the tests will still not work and I have not been able to add anything to the tsconfig.spec.json to get them working.
Environment:
chris13524 commentedon Apr 17, 2018
I've been following this thread for a while, but not sure if this has been mentioned before.
In my case, I'm doing the auto-rebuild stuff. So when I make a modification in my source, it'll rebuild and reload the browser page. The initial startup build always works, but after doing approximately 20 or more modifications and therefore rebuilds, I end up getting the out of memory error.
vandensd commentedon Apr 23, 2018
I have a fairly small project so it isn't the issue that the project itself will build and hit a memory limit. I ran into the memory issue after 10 or more repeated builds were run in TeamCity. Restarting the build agent/server got things back to normal, so it seems that memory is not being cleared after each build and eventually aggregating toward the limit.
fix(@ngtools/webpack): remove app decorators on AOT
fix(@angular/cli): update webpack, uglifyjs-webpack-plugin
Koslun commentedon Apr 23, 2018
@Ericdowney angular-cli 1.3.1 is quite old in this context. A lot has happened since then until 1.7.x. And a lot more is about to happen when they release 6.x. Might want to either switch to 1.7.x now and then use
ng updateto update to 6.x when that comes out and you also want to migrate to Angular 6.I wouldn't expect any fixes or help with angular cli version 1.3.1. Maybe version 6 will have similar LTS support but would always assume the latest version to give the best experience.
Enngage commentedon May 4, 2018
I previously had this error on Angular 5 with --aot flag and then it went away with the updates to @angular/cli. I have now upgraded to Angular 6 and the issue is back :/. I'm using:
ng serve myapp --prodAnd it fails with:
Any ideas how to fix these? It works fine when aot is disabled.
Koslun commentedon May 4, 2018
@Enngage
You can replace this line:
with one of the following alternatives
Alternative 1:
Create this npm script entry:
You can then in your console write:
Alternative 2:
Run this in the console:
Enngage commentedon May 5, 2018
Thank you @Koslun for this complete example. I went with the 1st approach and works well! I'm curious as to why this isn't mentioned anywhere in docs. This seems like any reasonably sized project would have to do anyway.
Koslun commentedon May 5, 2018
@Enngage think it's cause the goal is that this is never really supposed to happen. Where having to use this can often also instead be the result of some regression in angular-cli, Webpack or even Node, such as this fixed but unreleased regression in Node: nodejs/node#19769.
Given that this issue itself has the tag FAQ and the traffic it's garnered I agree that it might be worthwhile to add it to some FAQ in the documentation.
Arti3DPlayer commentedon May 13, 2018
Have the same issue and
sudo node --max-old-space-size=4096 /usr/local/bin/ionic cordova build android --proddidn't help. I'm using MacOs. Any advice ?aceleghin commentedon Jun 1, 2018
I am following this way: Inspect the bundles and I have the same error:
"devDependencies": { "@angular/cli": "^1.7.2", "@angular/compiler-cli": "^5.2.9",ZgjimDida commentedon Jun 1, 2018
@lippomano Try this. It solved the issue.
Marudhuraj commentedon Jul 26, 2018
My angular version is 5.1.1
Node version : 8
Npm version: 5
I have tried these command for AOT build even though i'm getting this ERROR JavaScript heap out of memory
Can you please any one knows how to solve this bug.
joshuwhi commentedon Jul 26, 2018
I've had the same issue and the only way I have solved it is to unfortunately use this flag:
--build-optimizer=falseKoslun commentedon Jul 26, 2018
@Marudhuraj Other than turning off build-optimizer, turning off source maps can also help. Would otherwise also in general recommend updating to latest angular-cli to get the best performance as well as ensure you're on Node version 8.11.2 or higher as there's a performance regression affecting Webpack builds of some versions below that in the 8.x series.
vandensd commentedon Jul 26, 2018
@joshuwhi @Koslun My personal experience was I was encountering this issue after 5 or more builds of the same app in succession on a team city agent. I have an opportunity to set up my CI on the latest Node, NPM, and Angular and will find some time in the next week or so to set up just the boilerplate ng new app building periodically throughout the day to see if the suggested dev environment versions mentioned here actually no longer reproduce the issue.
aryavijay commentedon Jul 26, 2018
@Marudhuraj
I solved this issue by doing the following step:
=================
@if EXIST "%~dp0\node.exe" (
"%~dp0\node.exe" --max_old_space_size=8192 "%~dp0..@angular\cli\bin\ng" %*
) ELSE (
@SETLOCAL
@set PATHEXT=%PATHEXT:;.JS;=;%
node --max_old_space_size=8192 "%~dp0..@angular\cli\bin\ng" %*
)
================
this is basically adding more memory for node to execute
3. Update the package.json file, by doing following steps:
replace
"build": "ng build",
by this:
"build": "ng build --prod --build-optimizer",
Thanks
Vijay
Marudhuraj commentedon Jul 27, 2018
Hi @aryavijay ,
Now i'm getting this error, how to resolve the app module factory error
ERROR in ./src/app/app.module.ngfactory.js
Module not found: Error: Can't resolve 'ngx-store/dist/src/service/local-storage.service' in 'C:\Users\a811891\taskmanagementv2ui\src\app' resolve 'ngx-store/dist/src/service/local-storage.service' in 'C:\Users\a811891\taskmanagementv2ui\src\app' Parsed request is a module using description file: C:\Users\a811891\taskmanagementv2ui\package.json (relative path: ./src/app) Field 'browser' doesn't contain a valid alias configuration after using description file: C:\Users\a811891\taskmanagementv2ui\package.json (relative path: ./src/app) resolve as module C:\Users\a811891\taskmanagementv2ui\src\app\node_modules doesn't exist or is not a directory C:\Users\a811891\taskmanagementv2ui\src\node_modules doesn't exist or is not a directory C:\Users\a811891\node_modules doesn't exist or is not a directory C:\Users\node_modules doesn't exist or is not a directory C:\node_modules doesn't exist or is not a directory looking for modules in C:\Users\a811891\taskmanagementv2ui\node_modules using description file: C:\Users\a811891\taskmanagementv2ui\package.json (relative path: ./node_modules) Field 'browser' doesn't contain a valid alias configuration after using description file: C:\Users\a811891\taskmanagementv2ui\package.json (relative path: ./node_modules) using description file: C:\Users\a811891\taskmanagementv2ui\node_modules\ngx-store\package.json (relative path: ./dist/src/service/local-storage.service) no extension Field 'browser' doesn't contain a valid alias configuration C:\Users\a811891\taskmanagementv2ui\node_modules\ngx-store\dist\src\service\local-storage.service doesn't exist .ts
yaadm commentedon Aug 6, 2018
I'm a noob, but this solved my problem,
Instead of:
ng build --prod
I wrote:
ng build --env prod
and it worked...
Please inform me if this answere is not good an why so i can expand my knowledge :)
Thanks.
kdubious commentedon Aug 6, 2018
@yaadm I think the
--envonly sets the environment.ts file, it doesn't set all the other production mode settings that--prodsets.williangd commentedon Aug 13, 2018
With Angular 6 the build time up from 600 seconds to 900 😞
Moulde commentedon Aug 14, 2018
I have the same issue.
with a production configuration that looks like this
fails with
But setting the flag: --max_old_space_size=8192 makes it work.
Node version: v8.11.3
Npm version: 6.3.0
liangwenzhong commentedon Aug 20, 2018
any solution to this ? ....
aryavijay commentedon Aug 20, 2018
read my comment or screenshare.....
Moulde commentedon Aug 20, 2018
@aryavijay I feel like setting max_old_space_size in various places is not really a solution, but rather a workaround.
This was not an issue before I upgraded the project and cli to angular 6.
paustint commentedon Aug 21, 2018
I am having the same issue, but it only occurs if I have
"sourceMap": true,inangular.json, otherwise it builds just fine.alfaproject commentedon Aug 22, 2018
I've just hit into this issue as well after upgrading to v6. It was working fine before. ):
williangd commentedon Aug 22, 2018
Is anyone else having problem with the build in 79% ModuleConcatenationPlugin? It's taking a long time and consuming a lot of memory.
dirkluijk commentedon Sep 9, 2018
This issue makes us unable to upgrade
@angular-devkit/build-angularfrom 0.6 to either 0.7 or 0.8.What is even worse, all mentioned workarounds (
buildOptimizer: false,sourceMap: false,--max_old_space_size=8192) do not work for our project.On
"@angular-devkit/build-angular": "0.6.3"everything works fine.iyashiyas commentedon Sep 14, 2018
I successfully build and serve with
node --max_old_space_size=8192 node_modules/@angular/cli/bin/ng serve --aot
but when i open my browser i got an error
ERROR Error: Uncaught (in promise): Error: Cannot find module 'app/pages/login/login.module'.
Error: Cannot find module 'app/pages/login/login.module'
with this version
Angular CLI: 1.5.2
Node: 6.10.3
@angular/.DS_Store: error
@angular/cdk: 5.2.5
@angular/cli: 1.5.2
@angular-devkit/build-optimizer: 0.0.42
@angular-devkit/core: 0.8.1
@angular-devkit/schematics: 0.0.52
@ngtools/json-schema: 1.1.0
@ngtools/webpack: 1.8.2
@schematics/angular: 0.1.17
typescript: 2.4.2
webpack: 3.8.1
i am tired with changing url in modules and changing versions last 48 hours. please help me.
dirkluijk commentedon Sep 14, 2018
@iyashiyas your issue seems unrelated to memory issues.
iyashiyas commentedon Sep 14, 2018
without node --max_old_space_size=8192 am getting
error JavaScript heap out of memory
dirkluijk commentedon Sep 14, 2018
@iyashiyas yes, so the workaround works well in your case and the "Cannot find module" error has nothing to do with this.
lawrencegrey commentedon Sep 19, 2018
Run the command through Node.js. That fixed my issue.
yharaskrik commentedon Sep 19, 2018
For anyone experiencing "JavaScript heap out of memory" when running a build:
I just upgraded to Angular 6 from 5 today and started getting these when building my universal server. I was on @nagular-devkit/angular-build: 0.8.0-rc8 and it kept failing. Downgrading to 0.6.3 worked as per: #5618 (comment)
Reverting sourcemaps as it now fails on out of memory:
wilsoncook commentedon Oct 12, 2018
@filipesilva Any debug way for us to figure out which big files cause huge memory use?
dirkluijk commentedon Oct 15, 2018
This issue was fixed - at least for our project - in
Angular 7.0.0-rc.0. I guess the CLI consumes less memory in that version...jiminikiz commentedon Oct 17, 2018
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.
ndraiman commentedon Oct 17, 2018
@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.
dobrinsky commentedon Oct 18, 2018
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
"aot": true(and "buildOptimizer": true because it depends on aot) I can publish the project.
iyashiyas commentedon Oct 18, 2018
before i face problem with java heap out of memory
and i run code with increasing memory but i failed with module error..
and i upgraded to angular 6 and successfully build with --prod mode
node --max_old_space_size=8192 'node_modules/@angular/cli/bin/ng' build --prod
Else you can set your angular.json
"build-prod": "node --max_old_space_size=8192 'node_modules/@angular/cli/bin/ng' build --prod ",
and call build-prod in u r command
now i am using --prod its more power full other than aot
radjivF commentedon Oct 19, 2018
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
Moulde commentedon Oct 19, 2018
Does this not work for you?
node --max_old_space_size=8192 'node_modules/@angular/cli/bin/ng' build --prod --build-optimizer
The --max_old_space_size argument is for node, not ng
filipesilva commentedon Oct 19, 2018
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
npmscript for this: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.
dobrinsky commentedon Oct 19, 2018
@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.
filipesilva commentedon Oct 19, 2018
@dobrinsky the code sample I showed was an npm script. Those scripts go into the
package.jsonfile, under thescriptskey:When you use have that script, you can use
npm run ng-high-memory --followed by the arguments instead ofnginside that project. Always use the double dash before arguments, otherwise they might not be parsed correctly.dobrinsky commentedon Oct 19, 2018
Thank you very much @filipesilva
It still won't work
ImranAhmed commentedon Oct 21, 2018
I started seeing this on my Azure DevOps Build server after upgrading to Angular 7.
Adding the following to
package.jsonand then calling this from my build task fixed it."build-prod": "node --max_old_space_size=8000 ./node_modules/@angular/cli/bin/ng build --prodsanidz commentedon Nov 16, 2018
If you have this problem with quagga js library , pay attention that "@angular/service-worker" is installed before "quagga": "^0.12.1" package.
mariohmol commentedon Nov 19, 2018
i could run with optimizejs using
node --max-old-space-size=8192 ./node_modules/@ionic/app-scripts/bin/ionic-app-scripts.js build --release --prod --minifyjs --minifycss --optimizejsHarelM commentedon Dec 3, 2018
For people who missed @dakotamurphyucf like I did:
using
increase-memory-limitpackage after running npm install will reduce all need to know where binary files are and will do it for all the files - which in my case is very useful since I'm running both regular build and cordova build.I'm using it only in my CI build script since locally it runs well.
basically:
npm install increase-memory-limit -gAnd run the command
increase-memory-limit.Pain is gone! No more suffering (for me at least)...
marcj commentedon Dec 6, 2018
Or just use
export NODE_OPTIONS=--max_old_space_size=4096which should fix it as well.jatinderkumargupta commentedon Dec 10, 2018
@marcj this solution worked for me.
I set NODE_OPTIONS for windows with following command:
set NODE_OPTIONS=--max_old_space_size=4096Installing increase-memory-limit, did not work for me on windows. I have not tried on linux/ubuntu or other OS.
HarelM commentedon Dec 10, 2018
@jatinderkumargupta Please note that it's not enough to install
increase-memory-limit, you need to run it also after npm installation of all packages has completed. I'm using windows and it worked for me.jatinderkumargupta commentedon Dec 10, 2018
Thanks @HarelM, I run that like you mentioned, but it did not work for me. May be some other problem then.
pdemro commentedon Dec 20, 2018
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..
bkarv commentedon Dec 23, 2018
@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?
ImranAhmed commentedon Dec 23, 2018
@bkarv
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.
bkarv commentedon Dec 23, 2018
I tried scripts but got errors. I ended up following the suggestion to export NODE_OPTIONS in OS and it worked. Many thanks
filipesilva commentedon Dec 27, 2018
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
package.jsonfile, under thescriptskey:When you use have that script, you can use
npm run ng-high-memory --followed by the arguments instead ofnginside that project. Always use the double dash before arguments, otherwise they might not be parsed correctly.