【随手记】前端多模块项目内存溢出
客怎眠qvq2024-03-282024-07-26
最近起公司的前端项目又爆内存了,忘记之前是怎么配置的,这篇博客用于备忘。
一个很臃肿的前端多模块项目,对应后端的多个 springboot
模块项目,前端每次启动都会对所有的包进行打包,影响启动速度,内存也很容易爆掉。
报错如下:
(node:28820) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 upgrade listeners added to [Server]. Use emitter.setMaxListeners() to increase limit
(Use `node --trace-warnings ...` to show where the warning was created)
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
1、使用 npm
安装插件
npm install -g increase-memory-limit
2、项目启动前,在终端运行对应命令
increase-memory-limit
# 或者下面这句
increase-memory-limit.cmd
3、在项目的 vue.config.js
中注释掉对应的内存限制行
console.log("CPU 数量", require('os').cpus().length)
console.log(require('v8').getHeapStatistics())
// args[0].memoryLimit = 4096; 这行限制注释掉
4、根据统一认证登录和单点登录的需要,修改 loginType
5、运行项目
npm run serve
# 或者
npm run dev
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有