angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

webpack ng serve runs out of memory

Open slubowsky opened this issue 10 years ago • 107 comments

Please provide us with the following information:

  1. OS? Windows 7, 8 or 10. Linux (which distribution). Mac OSX (Yosemite? El Capitan?) Windows 10
  2. Versions. Please run ng --version. If there's nothing outputted, please run in a Terminal: node --version and paste the result here: angular-cli: 1.0.0-beta.11-webpack.2 node: 6.3.1 os: win32 x64
  3. 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?)
  4. 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
  1. 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.

slubowsky avatar Aug 11 '16 20:08 slubowsky

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.

hansl avatar Sep 26 '16 20:09 hansl

ok. Not sure if this helps but it always crashes at the same point:

70% building modules 1345/1345 modules 0 active

mithun-daa avatar Sep 27 '16 12:09 mithun-daa

@hansl Are you guys still running out of memory on large apps? Wanted to check if the recent release fixed it.

mithun-daa avatar Oct 11 '16 14:10 mithun-daa

Is it related to https://github.com/angular/angular/issues/12184 ?

naveedahmed1 avatar Nov 03 '16 19:11 naveedahmed1

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

iwoogy avatar Nov 14 '16 12:11 iwoogy

Are you using AoT?

naveedahmed1 avatar Nov 14 '16 12:11 naveedahmed1

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.

iwoogy avatar Nov 14 '16 12:11 iwoogy

I don't use AoT either. I run out of memory on ng build or ng serve

mithun-daa avatar Nov 14 '16 15:11 mithun-daa

It's on ng serve. ng build works fine.

iwoogy avatar Nov 14 '16 15:11 iwoogy

Probably its due to the ngc, have a look at https://github.com/angular/angular-cli/issues/2981

Though you have mentioned you are not using AoT, but I still think the issue is with ngc if crashes for large projects.

naveedahmed1 avatar Nov 14 '16 15:11 naveedahmed1

Is there a way to fix it ?

iwoogy avatar Nov 14 '16 15:11 iwoogy

I found this article : Increasing Node.js memory limits

Is there a way to pass this argument (---max_old_space_size) to angular cli ?

iwoogy avatar Nov 15 '16 13:11 iwoogy

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

singhjusraj avatar Nov 15 '16 14:11 singhjusraj

@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.

naveedahmed1 avatar Nov 15 '16 15:11 naveedahmed1

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.

singhjusraj avatar Nov 15 '16 15:11 singhjusraj

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 ?

iwoogy avatar Nov 16 '16 04:11 iwoogy

I would guess that adding max-old-space-size to the system environment variables would do it - on Windows that is.

mithun-daa avatar Nov 16 '16 14:11 mithun-daa

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:

angular-cli: 1.0.0-beta.20-4
node: 6.9.1
os: win32 x64

Below is the log:

D:\MyProject>ng build --prod --aot
312982ms building modules
508ms sealing
16ms optimizing
1ms basic module optimization
299ms module optimization
5468ms advanced module optimization
136ms basic chunk optimization
0ms chunk optimization
21ms advanced chunk optimization
455ms building modules
1ms module and chunk tree optimization
1050ms module reviving
18ms module order optimization
48ms module id optimization
10ms chunk reviving
3ms chunk order optimization
44ms chunk id optimization
11288ms hashing
2ms module assets processing
1053ms chunk assets processing
9ms additional chunk assets processing
1ms recording
 91% additional asset processing
<--- Last few GCs --->

  680083 ms: Mark-sweep 1341.3 (1437.0) -> 1339.8 (1437.0) MB, 991.9 / 0.0 ms [allocation failure] [GC in old space requested].
  681044 ms: Mark-sweep 1339.8 (1437.0) -> 1339.8 (1437.0) MB, 960.9 / 0.0 ms [allocation failure] [GC in old space requested].
  682011 ms: Mark-sweep 1339.8 (1437.0) -> 1340.9 (1412.0) MB, 966.0 / 0.0 ms [last resort gc].
  682986 ms: Mark-sweep 1340.9 (1412.0) -> 1342.1 (1412.0) MB, 974.9 / 0.0 ms [last resort gc].


<--- JS stacktrace --->

==== JS stack trace =========================================

Security context: 0000019861ECFB61 <JS Object>
    1: /* anonymous */ [D:\MyProject\node_modules\webpack-sources\node_modules\source-map\lib\source-map-consumer.js:~142] [pc=000000411A16D6AE] (this=00000294368EDB49 <a BasicSourceMapConsumer with map 000003BC1D766499>,mapping=0000039E0356A939 <a Mapping with map 000003BC1D766C29>)
    2: arguments adaptor frame: 3->1
    3: map [native array.js:~994] [pc=000000411A15B70C] (thi...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

naveedahmed1 avatar Nov 16 '16 19:11 naveedahmed1

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 =========================================

2: arguments adaptor frame: 2->3

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

iwoogy avatar Nov 17 '16 06:11 iwoogy

@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.

kylecordes avatar Nov 17 '16 13:11 kylecordes