如何解决webpack执行时的内存溢出问题

Posted 张驰Terry

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何解决webpack执行时的内存溢出问题相关的知识,希望对你有一定的参考价值。

错误日志


recording


<--- Last few GCs --->

[45725:0x102884000]   269552 ms: Mark-sweep 1799.6 (1996.8) -> 1799.4 (1979.3) MB, 2002.7 / 0.0 ms  (average mu = 0.136, current mu = 0.000) last resort GC in old space requested
[45725:0x102884000]   271684 ms: Mark-sweep 1863.6 (2043.3) -> 1816.4 (2012.8) MB, 1518.6 / 0.0 ms  (+ 3.2 ms in 17 steps since start of marking, biggest step 2.2 ms, walltime since start of marking 1584 ms) (average mu = 0.207, current mu = 0.286) alloca

<--- JS stacktrace --->

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

Security context: 0x2bab917808a1 <JSObject>
    0: builtin exit frame: byteLength(aka byteLengthUtf8)(this=0x2baba3fb2741 <Object map = 0x2bab2eb65b91>,0x2babe5d44959 <Very long string[17266347]>,0x2baba3fb2741 <Object map = 0x2bab2eb65b91>)

    1: fromStringFast(aka fromStringFast) [0x2baba3faa339] [buffer.js:398] [bytecode=0x2bab539a85e1 offset=7](this=0x2babb6e004a9 <undefined>,0x2babe5d44959 <Very long string[17266347]>,0x2baba3fb274...

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - javascript heap out of memory
 1: 0x10007e9b3 node::Abort() [/usr/local/bin/node]
 2: 0x10007eb37 node::OnFatalError(char const*, char const*) [/usr/local/bin/node]
 3: 0x100176337 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 4: 0x1001762d3 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/local/bin/node]
 5: 0x1002fa485 v8::internal::Heap::FatalProcessOutOfMemory(char const*) [/usr/local/bin/node]
 6: 0x1002fbb54 v8::internal::Heap::RecomputeLimits(v8::internal::GarbageCollector) [/usr/local/bin/node]
 7: 0x1002f8a27 v8::internal::Heap::PerformGarbageCollection(v8::internal::GarbageCollector, v8::GCCallbackFlags) [/usr/local/bin/node]
 8: 0x1002f6a0d v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/local/bin/node]
 9: 0x100302124 v8::internal::Heap::AllocateRawWithLightRetry(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [/usr/local/bin/node]
10: 0x10030219f v8::internal::Heap::AllocateRawWithRetryOrFail(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [/usr/local/bin/node]
11: 0x1002d1073 v8::internal::Factory::NewRawTwoByteString(int, v8::internal::AllocationType) [/usr/local/bin/node]
12: 0x100517721 v8::internal::String::SlowFlatten(v8::internal::Isolate*, v8::internal::Handle<v8::internal::ConsString>, v8::internal::AllocationType) [/usr/local/bin/node]
13: 0x10019504d v8::String::Utf8Length(v8::Isolate*) const [/usr/local/bin/node]
14: 0x100061b16 node::Buffer::(anonymous namespace)::ByteLengthUtf8(v8::FunctionCallbackInfo<v8::Value> const&) [/usr/local/bin/node]
15: 0x1001e1650 v8::internal::FunctionCallbackArguments::Call(v8::internal::CallHandlerInfo) [/usr/local/bin/node]
16: 0x1001e0c2f v8::internal::MaybeHandle<v8::internal::Object> v8::internal::(anonymous namespace)::HandleApiCallHelper<false>(v8::internal::Isolate*, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::HeapObject>, v8::internal::Handle<v8::internal::FunctionTemplateInfo>, v8::internal::Handle<v8::internal::Object>, v8::internal::BuiltinArguments) [/usr/local/bin/node]
17: 0x1001e0330 v8::internal::Builtin_Impl_HandleApiCall(v8::internal::BuiltinArguments, v8::internal::Isolate*) [/usr/local/bin/node]
18: 0x100930d99 Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit [/usr/local/bin/node]
19: 0x1008b12e4 Builtins_InterpreterEntryTrampoline [/usr/local/bin/node]
[1]    45723 abort      npm run sdk

处理方法:

  1. 增加node运行内存(一般在package.json中配置)
{
    "scripts":{
        "sdk": "node --max_old_space_size=5048"
    }
}
  1. 清除运行缓存。因项目运行过程中造成了缓存,未及时释放导致。

以上是关于如何解决webpack执行时的内存溢出问题的主要内容,如果未能解决你的问题,请参考以下文章

.Net 内存溢出问题怎么才能很好的解决呢?

Vue-cli webpack 编译内存溢出

Java虚拟机——运行时的数据区域

如何检查和解决java虚拟机内存溢出的问题

spark内存溢出及其解决方案

怎么使用java Poi解决导入excel表格大数据量时的内存溢出问