vue编译报错JavaScript heap out of memory,node内存溢出,Exit status 134

报错:

0 info it worked if it ends with ok
1 verbose cli [ 'D:\\Program Files\\nodejs\\node.exe',
1 verbose cli   'D:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli   'run',
1 verbose cli   'dev' ]
2 info using npm@6.9.0
3 info using node@v10.16.0
4 verbose run-script [ 'predev', 'dev', 'postdev' ]
5 info lifecycle client-fms@1.0.0~predev: client-fms@1.0.0
6 info lifecycle client-fms@1.0.0~dev: client-fms@1.0.0
7 verbose lifecycle client-fms@1.0.0~dev: unsafe-perm in lifecycle true
8 verbose lifecycle client-fms@1.0.0~dev: PATH: D:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\node-gyp-bin;D:\workspace\xtb-III-project\client-fms\node_modules\.bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;D:\tools\jdk1.8\bin;D:\tools\maven\apache-maven-3.5.3\bin;D:\Program Files\Microsoft SQL Server\110\DTS\Binn\;D:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\;D:\Program Files\Microsoft SQL Server\110\Tools\Binn\;D:\Program Files (x86)\Microsoft SQL Server\110\Tools\Binn\ManagementStudio\;C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\;D:\Program Files (x86)\Microsoft SQL Server\110\DTS\Binn\;D:\Program Files\nodejs\;D:\Program Files\TortoiseSVN\bin;D:\MySQL\mysql-5.7.30-winx64\bin;;D:\Program Files\Microsoft VS Code\bin;C:\Users\Administrator.USER-20200630EX\AppData\Roaming\npm
9 verbose lifecycle client-fms@1.0.0~dev: CWD: D:\workspace\xtb-III-project\client-fms
10 silly lifecycle client-fms@1.0.0~dev: Args: [ '/d /s /c',
10 silly lifecycle   'webpack-dev-server --inline --progress --config build/webpack.dev.conf.js --env.CODE_ENV=development' ]
11 silly lifecycle client-fms@1.0.0~dev: Returned: code: 134  signal: null
12 info lifecycle client-fms@1.0.0~dev: Failed to exec dev script
13 verbose stack Error: client-fms@1.0.0 dev: `webpack-dev-server --inline --progress --config build/webpack.dev.conf.js --env.CODE_ENV=development`
13 verbose stack Exit status 134
13 verbose stack     at EventEmitter.<anonymous> (D:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\index.js:301:16)
13 verbose stack     at EventEmitter.emit (events.js:198:13)
13 verbose stack     at ChildProcess.<anonymous> (D:\Program Files\nodejs\node_modules\npm\node_modules\npm-lifecycle\lib\spawn.js:55:14)
13 verbose stack     at ChildProcess.emit (events.js:198:13)
13 verbose stack     at maybeClose (internal/child_process.js:982:16)
13 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:259:5)
14 verbose pkgid client-fms@1.0.0
15 verbose cwd D:\workspace\xtb-III-project\client-fms
16 verbose Windows_NT 6.1.7601
17 verbose argv "D:\\Program Files\\nodejs\\node.exe" "D:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "dev"
18 verbose node v10.16.0
19 verbose npm  v6.9.0
20 error code ELIFECYCLE
21 error errno 134
22 error client-fms@1.0.0 dev: `webpack-dev-server --inline --progress --config build/webpack.dev.conf.js --env.CODE_ENV=development`
22 error Exit status 134
23 error Failed at the client-fms@1.0.0 dev script.
23 error This is probably not a problem with npm. There is likely additional logging output above.
24 verbose exit [ 134, true ]


<--- JS stacktrace --->

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

    0: ExitFrame [pc: 000002B6A6D879E0]
Security context: 0x02dd6a41e6e9 <JSObject>
    1: byteLength(aka byteLength) [0000033958579241] [buffer.js:~509] [pc=000002B6A972F737](this=0x01f7db5026f1 <undefin
ed>,string=0x01dc4d3292b1 <Very long string[19967111]>,encoding=0x02dd6a43e2e1 <String[4]: utf8>)
    2: arguments adaptor frame: 3->2
    3: fromString(aka fromString) [0000015D1EE93251] [buffer.js:~334] [pc=000002B6A9246F10](this=0x01f7...

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory
 1: 000000013F39C6AA v8::internal::GCIdleTimeHandler::GCIdleTimeHandler+4506
 2: 000000013F377416 node::MakeCallback+4534
 3: 000000013F377D90 node_module_register+2032
 4: 000000013F69189E v8::internal::FatalProcessOutOfMemory+846
 5: 000000013F6917CF v8::internal::FatalProcessOutOfMemory+639
 6: 000000013F877F94 v8::internal::Heap::MaxHeapGrowingFactor+9620
 7: 000000013F87645B v8::internal::Heap::MaxHeapGrowingFactor+2651
 8: 000000013F9A02BB v8::internal::Factory::AllocateRawWithImmortalMap+59
 9: 000000013F9A2D6D v8::internal::Factory::NewRawTwoByteString+77
10: 000000013F6EDDA8 v8::internal::Smi::SmiPrint+536
11: 000000013F684EAB v8::internal::StringHasher::UpdateIndex+219
12: 000000013F6AA2C6 v8::String::Utf8Length+22
13: 000000013F3607AC node::Buffer::New+4332
14: 000002B6A6D879E0
npm ERR! code ELIFECYCLE
npm ERR! errno 134
npm ERR! client-fms@1.0.0 dev: `webpack-dev-server --inline --progress --config build/webpack.dev.conf.js --env.CODE_ENV
=development`
npm ERR! Exit status 134
npm ERR!
npm ERR! Failed at the client-fms@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!     C:\Users\Administrator.USER-20200630EX\AppData\Roaming\npm-cache\_logs\2020-10-21T08_53_56_044Z-debug.log

查询后了解到是Node中通过JavaScript使用内存时只能使用部分内存(64位系统:1.4 GB,32位系统:0.7 GB),如果前端项目比较大,Webpack编译时就会占用很多的系统资源,一旦超出了V8引擎对Node默认的内存限制大小时,就会产生内存溢出的错误。

方法一:

处理方式是:在package.json中script下添加

  "scripts": {
    "fix-memory-limit": "cross-env LIMIT=2048 increase-memory-limit",
    ...
  },
  "devDependencies": {
    "increase-memory-limit": "^1.0.7",
    "cross-env": "^5.2.0",
    ...
  }

接着执行 npm install cross-env --save–dev(目前这里只能使用npm)
以及 npm install increase-memory-limit --save–dev
如果安装失败则需要先删除掉项目的node_modules包
配置并安装成功后执行npm run fix-memory-limit这句,成功则会出现一下界面
vue编译报错JavaScript heap out of memory,node内存溢出,Exit status 134_第1张图片

方法二:

V8引擎对内存的使用的默认大小限制是1.4G,可以通过node.js命令设置限制来解决这个问题。修改package.json文件中内容,具体如下。

"serve": "npx --max_old_space_size=6144 vue-cli-service serve",
"build": "npx --max_old_space_size=6144 vue-cli-service build --modern"

修改完成后重启项目

方法三:

  1. 打开一个cmd窗口
  2. 运行setx NODE_OPTIONS --max_old_space_size=6144
  3. 关闭所有cmd窗口及代码编辑器
  4. 重新打开cmd并再次运行节点命令(npm命令等)

注意:方法二和方法三中的数字的大小不是固定的,可以按照电脑内存的大小以及项目编译时需要的大小来设置

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