Repository navigation
webpack ng serve runs out of memory #1652
Copy link
Copy link
Closed
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentAn issue that is relevant to core functions, but does not impede progress. Important, but not urgenteffort2: medium (days)
Description
Please provide us with the following information:
- OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?)
Windows 10 - Versions. Please run
ng --version. If there's nothing outputted, please run
in a Terminal:node --versionand paste the result here:
angular-cli: 1.0.0-beta.11-webpack.2
node: 6.3.1
os: win32 x64 - Repro steps. Was this an app that wasn't created using the CLI? What change did you
do on your code? etc.
Keep ng serve running and serving a cli built app while coding for some time (a few hours?) - The log given by the failure. Normally this include a stack trace and some
more information.
...
94% asset optimization
<--- Last few GCs --->
12936118 ms: Mark-sweep 1360.3 (1435.0) -> 1356.1 (1435.0) MB, 959.3 / 0 ms [all
ocation failure] [GC in old space requested].
12936973 ms: Mark-sweep 1356.1 (1435.0) -> 1356.0 (1435.0) MB, 854.9 / 0 ms [all
ocation failure] [GC in old space requested].
12938085 ms: Mark-sweep 1356.0 (1435.0) -> 1356.0 (1435.0) MB, 1112.2 / 0 ms [la
st resort gc].
12939012 ms: Mark-sweep 1356.0 (1435.0) -> 1355.8 (1435.0) MB, 926.7 / 0 ms [las
t resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 000001F1975C9E51 <JS Object>
1: replace [native string.js:~129] [pc=0000018EE86B74E5] (this=000000EF14282
331 <String[61]: D:/it/node_modules/@angular/common/src/pipes/common_pipes.js>,
N=000000EF140824C9 <JS RegExp>,O=00000135F03D7F21 <String[10]: !(webpack)>)
2: shorten [D:\it\node_modules\webpack\lib\RequestShortener.js:~41] [pc=000
0018EE4290DA2] (this=0000020E88D58019 <a RequestShortener with map 00000313C3C4.
..
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memo
ry
- Mention any other details that might be useful.
Only happened once so far but thought it worth mentioning
Thanks! We'll be in touch soon.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentAn issue that is relevant to core functions, but does not impede progress. Important, but not urgenteffort2: medium (days)
Activity
mithun-daa commentedon Sep 21, 2016
Any word on this? I just migrated from beta.10 to beta.15 and I am unable to
ng build. Get a similar error.Not sure if this has anything to do with it but I also got the following error while
npm i process-nextick-args util-deprecate(#1930)I am on node 4.x and unable to proceed.
mithun-daa commentedon Sep 26, 2016
@TheLarkInn @kylecordes @hansl Any help would be appreciated.
kylecordes commentedon Sep 26, 2016
@mithun-daa We have a team of people using CLI-webpack-edition here, and have helped numerous others get it up and running. We have noticed that it consumes quite a bit of memory which grows over time - the topic of this issue, but when we run on good development hardware it is very little practical problem. We just end up restarting CLI every couple of hours, no big deal. I think maybe the error you experience might be unrelated to the general issue here of leakage over time. A quick way to check and help provide more information for the CLI team to work from, is to simply try the exact same thing again on a machine with abundant RAM.
mithun-daa commentedon Sep 26, 2016
@kylecordes I wouldn't call my dev machine weak. These specs, I guess should be good enough:
kylecordes commentedon Sep 26, 2016
Right, that is obviously more than ample RAM. So I don't think the problem you are experiencing has anything to do with the somewhat exaggerated RAM usage and leakage over time that CLI+webpack currently experiences. I think you there some other problem in your project.
I suggest making a copy of your project, then incrementally trim away nearly all of it until you have a minimum reproduction case for the failure, something which you can publish to a public repository. That will then be a solid bug report which it is likely someone could reproduce and fix. Or you might find that by trimming away pieces you eventually find the bit which triggers this problem, also a great outcome. Good luck.
hansl commentedon Sep 26, 2016
@mithun-daa You can raise the heap size using
node --max_old_space_size=2048 ./node_modules/.bin/ng build. We (and the webpack team) are aware of some memory problems and @TheLarkInn is the one looking into it.mithun-daa commentedon Sep 26, 2016
@hansl will this work on Windows? Get the following error:
hansl commentedon Sep 26, 2016
@mithun-daa Oh on windows you have to replace
node_modules/.bin/ngbynode_modules\.bin\ng:)mithun-daa commentedon Sep 26, 2016
i did try with the
\instead of/with the same results.hansl commentedon Sep 26, 2016
mmmh, then I'm not sure. It seems like this is a problem with Node that using a full path doesn't work. On my VM using
node node_modules\.bin\ngdoes not work.mithun-daa commentedon Sep 26, 2016
Are there any prereqs? I am on Node 4.2.3. The global version of TS is different from the local version.
hansl commentedon Sep 26, 2016
Not really. Node 4.2 should work. I'm seeing a different error on my side but similar reason, with Node 6 on Windows 10.
mithun-daa commentedon Sep 26, 2016
@hansl If i create a new project using
ng neweverything works fine. but my existing app is massive and would like to avoid starting from scratch. I followed the directions in the Upgrade docs (beta.10 - beta.15).hansl commentedon Sep 26, 2016
Yes, I think the problem is the size of the app. We have that problem for one of our own as well, and there's no solution right now rather than just decrease the number of modules and/or components.
mithun-daa commentedon Sep 27, 2016
ok. Not sure if this helps but it always crashes at the same point:
70% building modules 1345/1345 modules 0 activemithun-daa commentedon Oct 11, 2016
@hansl Are you guys still running out of memory on large apps? Wanted to check if the recent release fixed it.
naveedahmed1 commentedon Nov 3, 2016
Is it related to angular/angular#12184 ?
iwoogy commentedon Nov 14, 2016
Hello,
I have this out of memory problem too.
If I restart ng serve it loads but at the next code update, the error kicks in.
I start having this problem with the recent increase in the complexity of the project.
Anyone has an idea how to increase the memory on node ?
Thanks
Here is the log :
webpack: bundle is now INVALID.
5539ms building modules
18ms sealing
0ms optimizing
0ms basic module optimization
154ms module optimization
1ms advanced module optimization
10ms basic chunk optimization
0ms chunk optimization
0ms advanced chunk optimization
34ms module and chunk tree optimization
183ms module reviving
8ms module order optimization
6ms module id optimization
12ms chunk reviving
2ms chunk order optimization
43ms chunk id optimization
143ms hashing
2ms module assets processing
191ms chunk assets processing
9ms additional chunk assets processing
0ms recording
0ms additional asset processing
92% chunk asset optimization
<--- Last few GCs --->
1051696 ms: Mark-sweep 1337.9 (1438.7) -> 1334.6 (1438.7) MB, 1522.6 / 0 ms [allocation failure] [GC in old space requested].
1053315 ms: Mark-sweep 1334.6 (1438.7) -> 1334.5 (1438.7) MB, 1619.3 / 0 ms [allocation failure] [GC in old space requested].
1054939 ms: Mark-sweep 1334.5 (1438.7) -> 1333.7 (1438.7) MB, 1623.8 / 0 ms [last resort gc].
1056597 ms: Mark-sweep 1333.7 (1438.7) -> 1333.7 (1438.7) MB, 1657.3 / 0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x3b457ffc9e59
2: addMapping(aka SourceMapGenerator_addMapping) [/(project_path)/node_modules/webpack-sources/node_modules/source-map/lib/source-map-generator.js:~94] [pc=0x13ba155d6c36](this=0x18debb29c861 <a SourceMapGenerator with map 0xe2aa00ac331>,aArgs=0x14fb4d43c101 <an Object with map 0xe2aa00abf69)
3: /* anonymous */ [/(project_path)/cli...
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::Localv8::Value, v8::Localv8::Message) [/usr/local/bin/node]
3: v8::internal::V8::FatalProcessOutOfMemory(char const_, bool) [/usr/local/bin/node]
4: v8::internal::Factory::NewUninitializedFixedArray(int) [/usr/local/bin/node]
5: v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::ConvertElementsWithCapacity(v8::internal::Handlev8::internal::JSObject, v8::internal::Handlev8::internal::FixedArrayBase, v8::internal::ElementsKind, unsigned int, unsigned int, unsigned int, int) [/usr/local/bin/node]
6: v8::internal::(anonymous namespace)::ElementsAccessorBase<v8::internal::(anonymous namespace)::FastPackedObjectElementsAccessor, v8::internal::(anonymous namespace)::ElementsKindTraits<(v8::internal::ElementsKind)2> >::GrowCapacityAndConvertImpl(v8::internal::Handlev8::internal::JSObject, unsigned int) [/usr/local/bin/node]
7: v8::internal::Runtime_GrowArrayElements(int, v8::internal::Object*, v8::internal::Isolate) [/usr/local/bin/node]
8: 0x13ba0f606338
Abort trap: 6
naveedahmed1 commentedon Nov 14, 2016
Are you using AoT?
iwoogy commentedon Nov 14, 2016
I think I'm not.
I just use : ng serve
without arguments.
I'm pretty new at this, so any explanation on how aot can help would be great.
mithun-daa commentedon Nov 14, 2016
I don't use AoT either. I run out of memory on
ng buildorng serveiwoogy commentedon Nov 14, 2016
It's on ng serve.
ng build works fine.
naveedahmed1 commentedon Nov 14, 2016
Probably its due to the ngc, have a look at #2981
Though you have mentioned you are not using AoT, but I still think the issue is with ngc if crashes for large projects.
iwoogy commentedon Nov 14, 2016
Is there a way to fix it ?
iwoogy commentedon Nov 15, 2016
I found this article : Increasing Node.js memory limits
Is there a way to pass this argument (---max_old_space_size) to angular cli ?
singhjusraj commentedon Nov 15, 2016
I don't use angular-cli but I was able to fix the node.js memory limit issue for ngc
Look at the answer here
naveedahmed1 commentedon Nov 15, 2016
@Singhsukhdeep that could be a workaround but not a permanent solution. and that only works on mac machine. And as you have mentioned you had to increase memory up to 8GB that might not be possible for many people.
singhjusraj commentedon Nov 15, 2016
Sure yes, it is nowhere a permanent solution. It is just a workaround to keep development moving for the time being until ngc gets better at memory management. We all have to apply workarounds all the time till things get better.
iwoogy commentedon Nov 16, 2016
Ok thanks for your answer.
By calling node directly this parameter --max-old-space-size=8192 solve the problem.
I'm using ng serve so is there a way to do like ng serve --max-old-space-size=8192 ?
Each time I change a file in the project the ng serve daemon crashed with OOM error.
I have to start ng serve again after each change.
The projet is not slowing down a bit, I'm a afraid that some day soon I won't be able even to start ng serve.
Any ideas guys how I can pass this parameter --max-old-space-size=8192 to ng serve ?
mithun-daa commentedon Nov 16, 2016
I would guess that adding
max-old-space-sizeto the system environment variables would do it - on Windows that is.naveedahmed1 commentedon Nov 16, 2016
I added max-old-space-size in system environment variables and increased value to 6144 but when I compile my project which uses lazy loading using latest version of angular cli (ng build --prod --aot) it fails with "JavaScript heap out of memory " error..
I am using:
Below is the log:
iwoogy commentedon Nov 17, 2016
Ok the time has come.
I cannot build the project anymore.
I restarted my computer with 16GB of RAM, and the project got to a point that compiling is not possible.
Please help...
Here is the log :
40239ms building modules
25ms sealing
0ms optimizing
0ms basic module optimization
160ms module optimization
1ms advanced module optimization
11ms basic chunk optimization
0ms chunk optimization
0ms advanced chunk optimization
0ms module and chunk tree optimization
207ms module reviving
3ms module order optimization
6ms module id optimization
13ms chunk reviving
9ms chunk order optimization
49ms chunk id optimization
4389ms hashing
3ms module assets processing
333ms chunk assets processing
17ms additional chunk assets processing
0ms recording
91% additional asset processing
<--- Last few GCs --->
121245 ms: Mark-sweep 1369.5 (1434.2) -> 1369.5 (1434.2) MB, 3483.5 / 0 ms [allocation failure] [GC in old space requested].
124715 ms: Mark-sweep 1369.5 (1434.2) -> 1369.5 (1434.2) MB, 3470.0 / 0 ms [allocation failure] [GC in old space requested].
128154 ms: Mark-sweep 1369.5 (1434.2) -> 1369.5 (1434.2) MB, 3439.0 / 0 ms [last resort gc].
131678 ms: Mark-sweep 1369.5 (1434.2) -> 1369.4 (1434.2) MB, 3523.9 / 0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x2b4cb30c9e59
3: input(aka next_token) [0x2b4cb3004189 :~1903] [pc=0x2d76545c6849](this=0x2f0fc1b4f169 <an Object with map 0x357947bce511>,force_regexp=0x2b4cb3004189 <undefined)
4: arguments adaptor frame: 0->1
5: /* anonymous /(aka / anonymous */) [0x2b4cb3004189 :~2151] [pc=0x2d76545effaa](this=0x2b4cb3004189 <undefined)
6: b...
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::Localv8::Value, v8::Localv8::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::TypeFeedbackVector::New(v8::internal::Isolate_, v8::internal::Handlev8::internal::TypeFeedbackMetadata) [/usr/local/bin/node]
6: v8::internal::CompilationInfo::EnsureFeedbackVector() [/usr/local/bin/node]
7: v8::internal::FullCodeGenerator::MakeCode(v8::internal::CompilationInfo_) [/usr/local/bin/node]
8: v8::internal::GenerateBaselineCode(v8::internal::CompilationInfo_) [/usr/local/bin/node]
9: v8::internal::GetUnoptimizedCodeCommon(v8::internal::CompilationInfo_) [/usr/local/bin/node]
10: v8::internal::Compiler::GetLazyCode(v8::internal::Handlev8::internal::JSFunction) [/usr/local/bin/node]
11: v8::internal::Runtime_CompileLazy(int, v8::internal::Object*, v8::internal::Isolate) [/usr/local/bin/node]
12: 0x2d765150961b
13: 0x2d7651531ed9
kylecordes commentedon Nov 17, 2016
@iwoogy Can you write any approximate statistics on the size of your project? Number of files, number of lines of code, how many of the files or components, that kind of thing? I would like to generate a fake application (programmatically) that generates this failure mode.
iwoogy commentedon Nov 17, 2016
Yes of course.
Do you have any tools that I can use to get the numbers you need ?
I read the all issue thread again and the post of @hansl helped me a lot.
This command :
node --max_old_space_size=2048 ./node_modules/.bin/ng build
was the one I was looking for.
I also use this syntax with ng serve and it does not crash anymore.
kylecordes commentedon Nov 17, 2016
I think CLOC is the easy for this purpose:
https://github.com/AlDanial/cloc
"npm install -g cloc"
iwoogy commentedon Nov 17, 2016
Ok this is the result :
kylecordes commentedon Nov 17, 2016
Is that just your "src" directory? If you run it at the top of the project, it might (I don't know what filtering it does built-in) count all the stuff in node_modules, which are potentially much larger than your application.
naveedahmed1 commentedon Nov 17, 2016
In my case:
It doens't include node_modules.
Below are the other modules my project uses:
iwoogy commentedon Nov 17, 2016
I ran cloc src
It does not include the node_modules.
kylecordes commentedon Nov 17, 2016
@naveedahmed1 That does not appear to be a particularly large application, I'm surprised at the size that it is bumping into RAM limitations in the build. It had been my impression the boundary was quite a lot further out. (Unless maybe some of those components/services/etc. have a remarkably large amount of code in them.)
@iwoogy Yours appears to be a quite large Angular project, that is more the size range I would expect to react the limits of the tools. I think at this point in the development of CLI, you might possibly need to pick up a more customized set of build tooling to work at that scale.
The key mystery is: why was one of these two projects was able to get so much larger before running into limitations? There might be a clue in there that could help the team fix the problem.
iwoogy commentedon Nov 17, 2016
Do you have any suggestions of the set of tools I should use for large projects ?
mithun-daa commentedon Nov 17, 2016
Here are my numbers

This is only my angular code in the
srcdirkylecordes commentedon Nov 17, 2016
About the additional numbers: if this is another example of a not-all-that-big application running up against the limits, it could be useful to the CLI team when their attention is on this item. At the moment is marked as "priority 3 nice to have", but maybe one of them will have an update on it.
About the question of other tools: typically the advice I've been giving (I work at a company where we help big companies launch their Angular efforts with training etc.) is that if CLI does not meet your needs yet, go look at the several available "seed" projects, experiment with each, and see which one seems like the closest fit. I don't have a list handy as I write this, but there are quite a few out there. (I also always give you advice: CLI is getting better all the time, even if you need to stop something else for a while, come back later!)
iwoogy commentedon Nov 17, 2016
CLI is working well so far, I would build on a separate machine with more RAM for now.
naveedahmed1 commentedon Nov 17, 2016
Ok, I was able to compile with ng build --aot --prod
@mithun-daa and @iwoogy can you please try this on Windows machine.
In node_modules.bin folder modify the below files and replace contents with the following:
Modify ng.cmd
Modify ngc.cmd
PS: In some cases you should be able to compile even without modifying ngc.cmd.
Restart machine and then in command prompt move to yourproject\node_modules.bin> directory and run below command:
ng build --aot --prodiwoogy commentedon Nov 17, 2016
Sorry guys, I don't have a Windows Machine.
naveedahmed1 commentedon Nov 17, 2016
One observation though I was able to compile with --prod --aot, the generated output files are quite large for example one the files 0.f3869100b45355cbf408.chunk.js is 8.7Mb and compilation took about 20 minutes.
iwoogy commentedon Nov 21, 2016
@kylecordes I have some new informations that may help.
I was using angular cli version beta.15.
ng serve with 4Gb of RAM was enough to run it.
I've just updated to version beta.20-4 and now I have to allocate 12Gb of RAM to avoid the out of memory problem.
kylecordes commentedon Nov 21, 2016
This is very good additional information, the CLI developers can see from this that the problem with this area is not only an old problem still needing attention eventually, it has worsened with recent betas.
iwoogy commentedon Nov 21, 2016
Some more context that might help.
I needed to upgrade angular-cli because I had to use lazy loading.
I'm wondering if the lazy loading feature is not the cause of the extra memory consumption.
mithun-daa commentedon Nov 21, 2016
@iwoogy How did you allocated the RAM? Using
max-old-space-size? I have a beefy Windows machine with 20GB of RAM and I still run out of memory.naveedahmed1 commentedon Nov 21, 2016
@mithun-daa have you tried #1652 (comment) ?
iwoogy commentedon Nov 21, 2016
My machine is 16GB of RAM, I think it swaps.
I have upgraded to version beta.18 now.
I have to use :
node --max_old_space_size=12288 ./node_modules/.bin/ng serve
filipesilva commentedon Dec 22, 2016
I'm changing the tag because it has an unfortunate name. It's not that I consider that not getting segfaults a nice to have, it's just that the
requiredtag mostly signals it should be there for final and we didn't have this well pinned down.hansl commentedon Feb 23, 2017
I don't think this is an actual issue that we can fix. We could take less memory and have some plans to have multiple processes in 2.0 which will alleviate this, but for now the workaround has to work.
aclowkey commentedon Feb 27, 2017
Hi guys,
I tried #issuecomment-261269197. I'm still getting the error. My app is reltively small - I have only 5 components..
jd-carroll commentedon Mar 24, 2017
@naveedahmed1 Can you please update your comment to have the following code:
This is necessary after the recent v1 release of the cli.
naveedahmed1 commentedon Mar 24, 2017
@jd-carroll in my case with Angular CLI V 1, I had to update max_old_space_size to 8048, so I believe the value would vary depending on the size of project.
marcalj commentedon Apr 3, 2017
For Mac or Linux users try with this command:
evanjmg commentedon Apr 18, 2017
I'm running into this issue as well because I have a large application. With @ngtools/webpack, any solutions for circleCI?
nadhir-falta commentedon Apr 18, 2017
Getting the same issue running
ng testRam: 16GB,
Windows 10
@angular/cli: 1.0.0
basherr commentedon Apr 20, 2017
Any work around?
basherr commentedon Apr 24, 2017
I resolved by navigating to
project/node_modulesfolder and run the following command:node --max_old_space_size=5048 "%~dp0\..\@angular\cli\bin\ng" build --aot --produredkar commentedon May 15, 2017
ng serve gives the following error to me. Basically stuck not sure what the next step is.
** NG Live Development Server is listening on localhost:4200, open your browser on http://localhost:4200 **
10% building modules 4/4 modules 0 active
<--- Last few GCs --->
155250 ms: Mark-sweep 1476.8 (1404.2) -> 1476.8 (1404.2) MB, 1379.6 / 0.0 ms [allocation failure] [GC in old space requested].
156704 ms: Mark-sweep 1476.8 (1404.2) -> 1476.8 (1404.2) MB, 1453.6 / 0.0 ms [allocation failure] [GC in old space requested].
158396 ms: Mark-sweep 1476.8 (1404.2) -> 1484.2 (1403.2) MB, 1690.8 / 0.0 ms [last resort gc].
159861 ms: Mark-sweep 1484.2 (1403.2) -> 1491.7 (1403.2) MB, 1465.7 / 0.0 ms [last resort gc].
<--- JS stacktrace --->
loixlab commentedon Jun 16, 2017
thanks @basherr !! this line saved my day 👍
MatellioRahul commentedon Jun 20, 2017
for windows machine you can try this
node --max_old_space_size=5120 "node_modules\@angular\cli\bin\ng" b --prod
where 5120 is the amount in mb you want to dedicate for the ng cli...
vjayanth commentedon Jun 27, 2017
@hansl @kylecordes I used node --max_old_space_size=2048 ./node_modules/.bin/ng build --prod cmd and it generated the files of 10mb main.js and 6 mb of vendor.js . how to decrease the size of this files now ?
xnnkmd commentedon Jul 14, 2017
@hansl This is a big problem and it remains unsolved - why is this closed ?
P.S. Are google using angular cli for projects? If so, I can't understand why google is not getting this error. It occurs for pretty much all big projects.
gtarun commentedon Jul 14, 2017
Facing the similar issue with ng build, I tried follwowing command as well but returned hell lot of errors. MacOs Sierra (256 SSD, 10 GB Ram)
node --max_old_space_size=7200 ./node_modules/.bin/ng build --prod --env=production --aot --output-hashing none--no-sourcemap
Please help guys it ruining our project deployment
danishin commentedon Jul 17, 2017
Facing this issue as well.
I gave it all of my 16GB memory of macbook pro.
It still failed with out-of-memory error. Not sure how to proceed from here...
My project isn't even that big. About 1 year old. I'm not sure how the rest of big companies using Angular deal with this?
xnnkmd commentedon Jul 17, 2017
@danishin could be a memory leak bug in angular- did you try to uncomment code using various kinds of angular features to find out what provokes the issue?
danishin commentedon Jul 18, 2017
@xnnkmd Hmm that could actually be the reason. Otherwise, out-of-memory error with 16GB for midsized project is too suspicious.
Do you have, by any chance, any list of angular features that might be a cause of memory leak? Afaik my project doesn't seem to do anything too outrageous wrt using angular features
tariknz commentedon Jul 18, 2017
It seems like if there is a template error then this could happen. Usually if you pass an arg to a function that doesn't have any args.
Adding enough memory will get you something like this:
TS2554: Expected 0 arguments, but got 1.But yeah I suspect the error is could be causing a memory leak somewhere? I'm not quite sure.
sonirahul commentedon Jul 18, 2017
i have noticed the memory consumption decreases if typescript code is optimised - like removing unused imports, unused methods, unused variables. also i noticed variables should be declared as "let" or "const" not var.. and last but not the least using tslint plugin i removed most of the code issues and my angular build memory consumption came down from 4gb to 2 gb.
Earlier my angular build was failing with 3gb and a minimum 4gb was required to build the prj but after doing the process mentioned above it started building with 2gb ram.
Forgot to mention - i am using idea intellij ultimate which shows many such issues in the angular code.
xnnkmd commentedon Jul 18, 2017
@danishin Sorry no - but you could start deleting more non-trival stuff like templates with pipes, ng-content etc, - just delete and delete until it builds and than put things back in until you find out what is responsible
xnnkmd commentedon Jul 18, 2017
@danishin BTW: How big is your mid-sized project measured in #components, #files, #source-code-lines ?
danishin commentedon Jul 18, 2017
@xnnkmd It's about 10K LOC of
.tsfiles. Not a big project at all. I realized that intsconfig.json,moduleis set tocommonjsinstead ofes2015as explained in here.Will try after making the changes. I have a feeling that what @tariknz said #1652 (comment) is the root cause of this. It seems that during the compilation, there was an error and memory leak because of it.
brunobertechini commentedon Aug 10, 2017
Just as a heads up. It turns out when I use YARN instead of NPM to RESTORE packages ng build completes successfully.
I am using
ng build --env=prod --aotWhen I restore packages using npm install -- same error from this issue (out of memory)
When I restore packages using yarn install -- no error - success
RicTheThird commentedon Aug 14, 2017
Thanks @basherr!
But instead of running script from command line.
Try running build script in package json by the following script:
then run "npm run build-prod"
chronicbint commentedon Aug 14, 2017
@RicTheThird and @basherr - worked for me, thanks.
scharlo commentedon Aug 22, 2017
@RicTheThird - thx. works for me. o/
By the way, i preferred changing the start script rather than adding a new one.
deepakanuraags commentedon Aug 25, 2017
"scripts": {
"ng-custom-serve": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng serve"
}
as suggested by @RicTheThird
this is what i have done to resolve,having ng serve as well,but will this hold good?,what if the application grows?Can we hope on this and go ahead?Any help would be great?
igorrius commentedon Sep 28, 2017
In my case problem was solved after force adding
@ngtools/webpackpackage todependencies. And using--max_old_space_sizeis was not required.muhammadsaaeed commentedon Oct 30, 2017
I've tried building project with latest webpack till date(i.e. @3.8.1) and it solved the similar issue for me.
finalxcode commentedon Nov 7, 2017
npm uninstall -g @angular/cli and reinstall @angular/cli@1.2.6 solved my problem
rejayi-experion commentedon Nov 10, 2017
I had experienced the issue
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memorywith 'ng build --prod'. I have solved the problem by usingnode --max_old_space_size=8192 node_modules/@angular/cli/bin/ng build --prodYou can add also in package.json as
npm run prodMartinFreire commentedon Nov 21, 2017
Hi, in my case, none of the solutions above worked for me.
I commented here about my execution crashing when it goes above 500 mb
I leave you here the link in case that thread is useful to someone
nhustak commentedon Nov 28, 2017
Thanks @rejayi-experion Modifying NG.cmd didn't work but just invoking it manually as you suggested did.
JBGoldberg commentedon Dec 11, 2017
Anyone have a more definitive solution for this? Anyone comment that @TheLarkInn is working in the issue. There is another thread open to this issue?
isahyarima commentedon Dec 29, 2017
node --max_old_space_size=2048 ./node_modules/.bin/ng Worked for me thanks
thecheeto commentedon Feb 8, 2018
For anyone that might be trying to debug why all of a sudden the build process started running out of memory, I was able to track the issue down to the following code in my project.
Before change (out of memory exception):
After change (no memory issues):
Using the code of the before change, every time that method was called, it caused more and more memory being used during
ng serveorng build.Not sure why specifying the return type fixes the issue, but went from
ng buildusing ~3gb of memory down to ~700mb.vitor-belim commentedon Feb 23, 2018
@thecheeto Did you add this modification to every function within your project? And even if it returns void?
thecheeto commentedon Feb 23, 2018
@vitor-belim No, only on that function. I'm thinking it has something to do with differing return types in a function. In my case it was returning either an
ErrorObservableorObservable<{success: boolean, errors: string[]}>.prudhvichitturi commentedon Jan 28, 2019
This has been changed in angular 7 now. I couldn't able to find the path of ng.. Please any help for finding its path in node modules..
`> node --max_old_space_size=5048 ng build --prod --aot --source-map=false
module.js:540
throw err;
^
Error: Error: Cannot find module '/Users/work/ui/node_modules/@angular/cli/bin/ng'
at Function.Module._resolveFilename (module.js:538:15)
at Function.Module._load (module.js:468:25)
at Function.Module.runMain (module.js:684:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! data-ui@1.0.0 build-script-a7: node --max_old_space_size=5048 ng build --prod --aot --source-map=false
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the data-ui@1.0.0 build-script-a7 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! /Users/.npm/_logs/2019-01-28T08_13_45_344Z-debug.log
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! data-ui@1.0.0 build: npm run config -- --environment=prod && npm run build-script-a7 && npm run prod-server
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the data-ui@1.0.0 build 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! /Users/.npm/_logs/2019-01-28T08_13_45_364Z-debug.log`
strizich commentedon Jan 31, 2019
@prudhvichitturi
node --max_old_space_size=5048 ./node_modules/.bin/<ng command>httpete commentedon Feb 15, 2019
this worked for me:
"start": "node --max_old_space_size=5048 ./node_modules/@angular/cli/bin/ng serve",uriel2095 commentedon Apr 17, 2019
this is simple and fuction for me :3
pauldraper commentedon Apr 18, 2019
It's weird that I have to tell Angular CLI/Node.js how much memory it can use.
Chrome/V8 seems happy to use all my memory.
angular-automatic-lock-bot commentedon Sep 9, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.