Question

My script is failing when attempting to load the template, with the following error:

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

The code that I'm calling looks like this:

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);
                    }
                });
            }
        });
    }
});

It gets as far as Found that today is xxx and the winston.error inside doesn't get called. What's causing that? A dodgy template perhaps?

Was it helpful?

Solution

After a lot of digging and debugging, I've managed to find the cause of this issue. I am using the node-email-templates which uses EJS to process JavaScript code within a HTML template and then email it using Nodemailer.

The problem occurs within the EJS module, specifically when trying to process variables within comments.

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

The code within the comment <%= time %> causes a crash somewhere along the line. I've reported this bug on the GitHub issues page of EJS. I'm going to attempt to fix it when I get some time at work.

OTHER TIPS

I ran into this same error, but my issue was that html2text was breaking one of my variables onto two lines, like

<%= var
%>

After correcting this so that the variable was all on one line, I no longer got the allocation error.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top