2013-04-25 26 views
0

我的脚本失败:致命错误:JS分配失败当试图加载模板,并出现以下错误

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 <[email protected]>", 
        to: "[email protected]", 
        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 xxxwinston.error里面不会被调用。这是什么原因造成的?也许是一个狡猾的模板?

回答

1

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

该问题发生在EJS模块内,特别是当试图处理变量注释时。

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

<%= time %>导致系统崩溃沿线某处的注释中的代码。我在EJS的GitHub问题页面上有reported this bug。当我有时间工作时,我会试图修复它。

0

我碰到了同样的错误,但我的问题是,html2text被打破我的变量之一成两行,像

<%= var 
%> 

纠正这一点,以便该变量都在同一行,我没有后更长的分配错误。

相关问题