流星构建运行我们的内存 [英] Meteor build running our of memory
问题描述
我正在尝试构建我的流星应用程序,但不断遇到以下错误.这不是我第一次构建应用程序,并且在昨天的构建之前一切正常.我已经尝试过:正如 [this SO post][1] 中的一个答案中所建议的那样,但它没有帮助.
I'm trying to build my meteor app and am constantly running into the below error. This is not the first time I'm building the app and everything worked fine until yesterday's build. I already tried: as suggested in one of the answeres in [this SO post][1] but it did not help.
#!/usr/bin/env node --max_old_space_size=4096 --optimize_for_size --max_executable_size=4096 --stack_size=4096
控制台输出:
meteor build .
WARNING: The output directory is under your source tree.
Your generated files may get interpreted as source code!
Consider building into a different directory instead
meteor build ../output
Minifying app code \
<--- Last few GCs --->
103230 ms: Mark-sweep 1385.5 (1455.5) -> 1387.9 (1455.5) MB, 898.4 / 0 ms [allocation failure] [GC in old space requested].
104206 ms: Mark-sweep 1387.9 (1455.5) -> 1387.9 (1455.5) MB, 975.8 / 0 ms [allocation failure] [GC in old space requested].
105196 ms: Mark-sweep 1387.9 (1455.5) -> 1384.1 (1455.5) MB, 990.2 / 0 ms [last resort gc].
106101 ms: Mark-sweep 1384.1 (1455.5) -> 1385.1 (1455.5) MB, 905.3 / 0 ms [last resort gc].
<--- JS stacktrace --->
==== JS stack trace =========================================
Security context: 0x249f6fdb4629 <JS Object>
1: /* anonymous */(aka /* anonymous */) [0x249f6fd041b9 <undefined>:~4943] [pc=0xcd10dd2f48c] (this=0x249f6fd041b9 <undefined>,self=0x1400b413881 <an AST_ObjectKeyVal with map 0xc3d3a4651b9>,output=0x17417c4edd79 <an Object with map 0x16588927e021>)
2: doit(aka doit) [0x249f6fd041b9 <undefined>:4190] [pc=0xcd10d7a3298] (this=0x249f6fd041b9 <undefined>)
3: print [0x249f6fd041b9 <unde...
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - process out of memory
Aborted (core dumped)
推荐答案
同样的问题让我发疯,但我终于在meteor 1.4.3.1下解决了.
This same issue was driving me nuts, but I finally managed to resolve it under meteor 1.4.3.1.
背景:
问题是meteor 调用node 来构建.当它运行时,node 会为其运行的 V8 引擎分配一定数量的内存.在较大的项目中,为 V8 分配的默认内存不足以跟踪所有内容 - 它试图在接近限制时进行垃圾收集,但最终空间不足并崩溃并显示错误.
The issue is that meteor calls node to build. When it runs, node allocates a certain amount of memory for the V8 engine it runs on. In bigger projects, the default memory allocated for V8 is not sufficient to keep track of everything - it tried to garbage-collect as it gets closer to the limit, but eventually runs out of space and crashes with the error shown.
如果我们只是直接运行 node,我们可以使用 --max-old-space-size 选项运行它,这将允许我们设置 V8 引擎的最大内存.问题在于,meteor 在它自己的上下文中调用 node 并使用它自己的选项,所以我们不能直接将标志添加到我们的meteor 调用中.
If we were just running node directly, we could run it with the --max-old-space-size option, which would allow us to set the maximum memory for the V8 engine. The issue is that meteor calls node in its own context and with its own options, so we can't just add the flag directly to our meteor call.
解决方案:
看来,meteor 1.4.3.1(可能还有其他人)在调用节点时会传递在 TOOL_NODE_FLAGS 环境变量中指定的标志和选项(其他人提到了 NODE_OPTIONS,但它不适用于我的meteor 版本 -标志只是被丢弃)
It appears that meteor 1.4.3.1 (and maybe others) will pass along flags and options specified in the TOOL_NODE_FLAGS environment variable when it calls node (others have mentioned NODE_OPTIONS, but it isn't working for my version of meteor - the flags just get dropped)
所以如果你想把节点引擎的最大内存增加到4GB,添加一个环境变量
So if you want to increase the max memory of the node engine to 4 GB, add an environmental variable
TOOL_NODE_FLAGS="--max-old-space-size=4096"
到您正在运行meteor 的上下文 - 该选项应该传递给节点调用.
to the context you are running meteor in - the option should be passed through to the node call.
(如果您不知道在哪里设置环境变量 - 它通常会在您的 IDE 构建配置或构建脚本中.如果您想健全检查 --max-old... 选项是否实际上是正在阅读,请尝试将其更改为乱码-它应该会导致meteor 抛出错误)
(If you don't know where to set environment variables - it is usually going to be in your IDE build configuration or build script. If you want to sanity check if the --max-old... option is actually being read, try changing it to gibberish - it should cause meteor to throw an error)
这篇关于流星构建运行我们的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!