vue项目热更新内存溢出问题

vue项目启动后,每次修改部分代码,再编译和打包时会频繁内存溢出,都会导致项目运行中断。有的同事是时不时会中断,我是每次都会中断

报错信息如下:

> node –max_old_space_size=4096 webpack-dev-server --inline --progress --config build/webpack.dev.conf.js

module.js:549
    throw err;
    ^

Error: Cannot find module 'F:\work\路径\路径\vue\–max_old_space_size=4096'
    at Function.Module._resolveFilename (module.js:547:15)
    at Function.Module._load (module.js:474:25)
    at Function.Module.runMain (module.js:693:10)
    at startup (bootstrap_node.js:188:16)
    at bootstrap_node.js:609:3
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! house-vue@1.0.0 dev: `node –max_old_space_size=4096 webpack-dev-server --inline --progress --config build/webpack.dev.conf.js`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the house-vue@1.0.0 dev 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!     D:\Program Files\nodejs\X64\node_cache\_logs\2018-09-04T07_52_06_975Z-debug.log

同事们的解决方法(见链接):
https://www.cnblogs.com/maqingyuan/p/10636920.html
但对于我的电脑不适用,除了安装 fix-memory-limit插件之外,还另外做了以下配置

// 找到以下路径
./node_modules/.bin/webpack-dev-server.cmd

// 在node后面增加    --max-old-space-size=4096
@IF EXIST "%~dp0\node.exe" (
  "%~dp0\node.exe"  "%~dp0\..\webpack-dev-server\bin\webpack-dev-server.js" %*
) ELSE (
  @SETLOCAL
  @SET PATHEXT=%PATHEXT:;.JS;=;%
  node  --max-old-space-size=4096 "%~dp0\..\webpack-dev-server\bin\webpack-dev-server.js" %*
)

至此解决项目热更新时,每次保存会报错的问题。

vue项目热更新内存溢出问题_第1张图片
但直到上周调试项目,删除了node_modules,并重新安装依赖后又开始出现热加载内存溢出的问题,但是之前安装的插件和修改的配置依旧在(无语)。
vue项目热更新内存溢出问题_第2张图片
vue项目热更新内存溢出问题_第3张图片
主要报错信息:Ineffective mark-compacts near heap limit Allocation failed - JavaScript hea,完整如下:

 FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed 
    - 
    JavaScript heap out of memory
    1: 000000013F56F04A 
       v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+5114
    2: 000000013F54A0C6 node::MakeCallback+4518
    3: 000000013F54AA30 node_module_register+2032
    4: 000000013F7D20EE v8::internal::FatalProcessOutOfMemory+846
    5: 000000013F7D201F v8::internal::FatalProcessOutOfMemory+639


    6: 000000013FCF2BC4 v8::internal::Heap::MaxHeapGrowingFactor+9556

     7: 000000013FCE9C46 v8::internal::ScavengeJob::operator=+24310
     8: 000000013FCE829C v8::internal::ScavengeJob::operator=+17740
     9: 000000013FCEE1B7 v8::internal::Heap::CreateFillerObjectAt+1175
    10: 000000013FB7C5B3 
    v8::internal::interpreter::Interpreter::GetDispatchCounters
    Object+78451
    11: 000000013F4D1132 
        v8::internal::StackGuard::ArchiveSpacePerThread+52082
    12: 000000013F4D17F3 
        v8::internal::StackGuard::ArchiveSpacePerThread+53811
    13: 000000013F5B1474 uv_dlerror+2436
    14: 000000013F5B21D8 uv_run+232

15: 000000013F55128E node::NewContext+1390
16: 000000013F55189B node::NewIsolate+603
17: 000000013F551D07 node::Start+839
18: 000000013F40935C node::MultiIsolatePlatform::MultiIsolatePlatform+604
19: 000000013FFAA93C 
   v8::internal::compiler::OperationTyper::ToBoolean+134796
20: 0000000076D3555D BaseThreadInitThunk+13
21: 0000000076F9385D RtlUserThreadStart+29

<--- Last few GCs --->

[13304:0000000000182610]   135335 ms: Mark-sweep 1396.6 (1426.7) -> 1396.6 (1424
.7) MB, 2368.0 / 0.0 ms  (+ 0.0 ms in 1 steps since start of marking, biggest st
ep 0.0 ms, walltime since start of marking 2368 ms) (average mu = 0.099, current
 mu = 0.035) fi[13304:0000000000182610]   135404 ms: Scavenge 1397.6 (1424.7) ->
 1397.1 (1428.2) MB, 3.7 / 0.0 ms  (average mu = 0.099, current mu = 0.035) allo
cation failure


<--- JS stacktrace --->

FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - 
JavaS
cript heap out of memory
 1: 000000013FD7F04A v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+5114
 2: 000000013FD5A0C6 node::MakeCallback+4518
 3: 000000013FD5AA30 node_module_register+2032
 4: 000000013FFE20EE v8::internal::FatalProcessOutOfMemory+846
 5: 000000013FFE201F v8::internal::FatalProcessOutOfMemory+639
 6: 0000000140502BC4 v8::internal::Heap::MaxHeapGrowingFactor+9556
 7: 00000001404F9C46 v8::internal::ScavengeJob::operator=+24310
 8: 00000001404F829C v8::internal::ScavengeJob::operator=+17740
 9: 00000001404FE1B7 v8::internal::Heap::CreateFillerObjectAt+1175
10: 000000014038C5B3 
    v8::internal::interpreter::Interpreter::GetDispatchCounters
    Object+78451
11: 000000013FCE1132 v8::internal::StackGuard::ArchiveSpacePerThread+52082
12: 000000013FCE17F3 v8::internal::StackGuard::ArchiveSpacePerThread+53811
13: 000000013FDC1474 uv_dlerror+2436
14: 000000013FDC21D8 uv_run+232
15: 000000013FD6128E node::NewContext+1390
16: 000000013FD6189B node::NewIsolate+603
17: 000000013FD61D07 node::Start+839
18: 000000013FC1935C node::MultiIsolatePlatform::MultiIsolatePlatform+604
19: 00000001407BA93C 
   v8::internal::compiler::OperationTyper::ToBoolean+134796
20: 0000000076D3555D BaseThreadInitThunk+13
21: 0000000076F9385D RtlUserThreadStart+29

各种百度后,大多建议安装fix-memory-limit,或者在package.json文件的script调试中,增加--max-old-space-size=4096
因为fix-memory-limit已经存在,尝试直接执行npm run fix-memory-limit命令,再启动项目发现又可以了。

vue项目热更新内存溢出问题_第4张图片

你可能感兴趣的:(vue.js,javascript,webpack,缓存,node.js)