构建 Vue.js 应用程序时 JavaScript 堆内存不足 [英] JavaScript heap out of memory when building Vue.js app
问题描述
我正在尝试构建一个用于生产的 vue.js 应用程序.此错误消息总是在中途出现.
I'm trying to build a vue.js app for production. This error message always appears midway through.
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
我已经尝试通过添加--max_old_space_size=4096
来增加内存,甚至尝试将其更改为8192,但无济于事.我使用的是带有 8 GB RAM 的 Mac,所以我不确定为什么会发生这种情况.
I already tried to increase the memory by adding --max_old_space_size=4096
and even tried to change it to 8192, but to no avail. I am using a Mac with 8 GB of RAM so I'm not sure why this is happening.
这是我为 npm run build 运行的代码:
This is the code I run for npm run build:
vue-cli-service build --max_old_space_size=4096
推荐答案
我也遇到了这个问题.内存限制与 Node 有关,因此运行此命令有效:
I ran into this problem too. The memory limitation was with Node so running this command worked:
NODE_OPTIONS=--max_old_space_size=4096 npm run build
Node 的默认内存限制为 512MB,运行此命令暂时将其增加到 4GB.
The default memory limit for Node is 512MB, running this command temporarily increased it to 4GB.
这篇关于构建 Vue.js 应用程序时 JavaScript 堆内存不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!