致命错误:JS分配失败

时间:2013-04-25 10:05:36

标签: node.js nodemailer

尝试加载模板时,我的脚本失败,出现以下错误:

FATAL ERROR: JS Allocation failed - process out of memory exited with code 5

我正在调用的代码如下:

emailTemplates(templatesDir, function(err, template) {
    winston.info("Setting up templates.", templatesDir);
    if(err) {
        winston.error(err);
    }else{
        var today = new Date().getDay();
        winston.info("Found that today is ", aDays[today]);

        template("notify", {
            reports: [{
                item: "merged",
                desc: "Blah blah"
            },{
                item: "searched",
                desc: "Blah blah"
            }],
            vars: Operators.BBT.mail,
            day: aDays[today],
            fusionAPIRan: canRunFAPI
        }, function(err, html, text) {
            if(err) {
                winston.error(err);
            }else{
                winston.info("Attempting to send an email!");
                smtpTransport.sendMail({
                    from: "Webmaster <webmaster@example.co.uk>",
                    to: "james@example.co.uk",
                    subject: "Worker - Notification Email",
                    html: html
                }, function(error, response){
                    if(error){
                        winston.error(error);
                        cb(false);
                    }else{ 
                        winston.info("Message sent: " + response.message + ", message id: " + response.messageId);
                        cb(true);
                    }
                });
            }
        });
    }
});

它到Found that today is xxx并且内部的winston.error没有被调用。是什么原因造成的?一个狡猾的模板也许?

2 个答案:

答案 0 :(得分:1)

经过大量的挖掘和调试,我找到了这个问题的原因。我使用node-email-templates使用EJS处理HTML模板中的JavaScript代码,然后使用Nodemailer通过电子邮件发送。

问题出现在EJS模块中,特别是在尝试处理评论中的变量时。

<!-- The entire job took <%= time => to complete. -->

评论<%= time %>中的代码会导致崩溃。我在EJS的GitHub问题页面上reported this bug。当我在工作时间时,我会尝试修复它。

答案 1 :(得分:0)

我遇到了同样的错误,但我的问题是html2text将我的一个变量分成两行,比如

<%= var
%>

在纠正这个以使变量全部在一行之后,我不再得到分配错误。