yads / nodemailer-express-handlebars

A plugin for nodemailer that uses express-handlebars view engine to generate emails
87 stars 30 forks source link

“A partials dir must be a string or config object” using nodemailer-express-handlebars in Firebase Functions #22

Closed Tomdrouv1 closed 5 years ago

Tomdrouv1 commented 5 years ago

Hi,

I'm facing an issue for 2 weeks now when I'm using this library in my project hosted in Firebase.

This function works well in local environment and worked well before but now this issue appears, like if my path in the handlebars configuration disappears.

mailTransport.use('compile', hbs({viewEngine: '.handlebars', viewPath: templateDir}));

templateDir is a string of course but in the Firebase Functions console the issue “A partials dir must be a string or config object” appears.

Any idea of what it may be?

Thanks

neon-sombrero commented 5 years ago

I'm seeing this also. Looks like there was a change in express-handlebars which nodemailer-express-handlebars depends on. See here.

neon-sombrero commented 5 years ago

I managed to get my code working, posting in case it helps out. I had to add the partialsDir to my handlebarOptions where I didn't have the field before:

const handlebarOptions = {
  viewEngine: {
    extName: '.hbs',
    partialsDir: 'some/path',
    layoutsDir: 'some/path',
    defaultLayout: 'email.body.hbs',
  },
  viewPath: 'some/path',
  extName: '.hbs',
};

transporter.use('compile', hbs(handlebarOptions));

The partialsDir must have been an optional field at one point, but now seems to be required. Hope this helps.

GahFlorencio commented 5 years ago

I managed to get my code working, posting in case it helps out. I had to add the partialsDir to my handlebarOptions where I didn't have the field before:

const handlebarOptions = {
  viewEngine: {
    extName: '.hbs',
    partialsDir: 'some/path',
    layoutsDir: 'some/path',
    defaultLayout: 'email.body.hbs',
  },
  viewPath: 'some/path',
  extName: '.hbs',
};

transporter.use('compile', hbs(handlebarOptions));

The partialsDir must have been an optional field at one point, but now seems to be required. Hope this helps.

Works for me thanks a lot now the partialsDir is required i just put it on code and BANG worked ! , thanks again !

roxdavirox commented 5 years ago

I managed to get my code working, posting in case it helps out. I had to add the partialsDir to my handlebarOptions where I didn't have the field before:

const handlebarOptions = {
  viewEngine: {
    extName: '.hbs',
    partialsDir: 'some/path',
    layoutsDir: 'some/path',
    defaultLayout: 'email.body.hbs',
  },
  viewPath: 'some/path',
  extName: '.hbs',
};

transporter.use('compile', hbs(handlebarOptions));

The partialsDir must have been an optional field at one point, but now seems to be required. Hope this helps.

works for me using partialsDir, thanks

richard4s commented 5 years ago

Incase anyone wonders why it still doesn't work, check out this last line, take note of the hbs function transporter.use('compile', hbs(handlebarOptions)); and change it to mailerhbs transporter.use('compile', mailerhbs(handlebarOptions));

denisgianne commented 5 years ago

I managed to get my code working, posting in case it helps out. I had to add the partialsDir to my handlebarOptions where I didn't have the field before:

const handlebarOptions = {
  viewEngine: {
    extName: '.hbs',
    partialsDir: 'some/path',
    layoutsDir: 'some/path',
    defaultLayout: 'email.body.hbs',
  },
  viewPath: 'some/path',
  extName: '.hbs',
};

transporter.use('compile', hbs(handlebarOptions));

The partialsDir must have been an optional field at one point, but now seems to be required. Hope this helps.

Works for me too, using the partialDir. Thanks!

aman-anand commented 5 years ago

I managed to get my code working, posting in case it helps out. I had to add the partialsDir to my handlebarOptions where I didn't have the field before:

const handlebarOptions = {
  viewEngine: {
    extName: '.hbs',
    partialsDir: 'some/path',
    layoutsDir: 'some/path',
    defaultLayout: 'email.body.hbs',
  },
  viewPath: 'some/path',
  extName: '.hbs',
};

transporter.use('compile', hbs(handlebarOptions));

The partialsDir must have been an optional field at one point, but now seems to be required. Hope this helps.

works

1510143 commented 5 years ago

I managed to get my code working, posting in case it helps out. I had to add the partialsDir to my handlebarOptions where I didn't have the field before:

const handlebarOptions = {
  viewEngine: {
    extName: '.hbs',
    partialsDir: 'some/path',
    layoutsDir: 'some/path',
    defaultLayout: 'email.body.hbs',
  },
  viewPath: 'some/path',
  extName: '.hbs',
};

transporter.use('compile', hbs(handlebarOptions));

The partialsDir must have been an optional field at one point, but now seems to be required. Hope this helps.

It works. But when I used different template to send email. The default template still used. My code:

var handlebarsOptions = {
    viewEngine: {
        extName: '.html',
        partialsDir: path.resolve('./views/templates/'),
        layoutsDir: path.resolve('./views/templates/'),
        defaultLayout: 'forgot-password-email.html',
    },
    viewPath: path.resolve('./views/templates/'),
    extName: '.html'
};
smtpTransport.use('compile', hbs(handlebarsOptions));
var data = {
                            from: process.env.EMAIL,
                            to: user.email,
                            template: 'reset-password-success-email',
                            subject: 'Password Reset Confirmation',
                            context: {
                                name: user.name
                            }
                        };
smtpTransport.sendMail(data);

Please help.

amr3mmar commented 5 years ago

I managed to get my code working, posting in case it helps out. I had to add the partialsDir to my handlebarOptions where I didn't have the field before:

const handlebarOptions = {
  viewEngine: {
    extName: '.hbs',
    partialsDir: 'some/path',
    layoutsDir: 'some/path',
    defaultLayout: 'email.body.hbs',
  },
  viewPath: 'some/path',
  extName: '.hbs',
};

transporter.use('compile', hbs(handlebarOptions));

The partialsDir must have been an optional field at one point, but now seems to be required. Hope this helps.

It works. But when I used different template to send email. The default template still used. My code:

var handlebarsOptions = {
    viewEngine: {
        extName: '.html',
        partialsDir: path.resolve('./views/templates/'),
        layoutsDir: path.resolve('./views/templates/'),
        defaultLayout: 'forgot-password-email.html',
    },
    viewPath: path.resolve('./views/templates/'),
    extName: '.html'
};
smtpTransport.use('compile', hbs(handlebarsOptions));
var data = {
                            from: process.env.EMAIL,
                            to: user.email,
                            template: 'reset-password-success-email',
                            subject: 'Password Reset Confirmation',
                            context: {
                                name: user.name
                            }
                        };
smtpTransport.sendMail(data);

Please help.

I had the same issue, just set the defaultLayout to an empty string and it'll depend on the template in the mailoptions:

const handlebarOptions = {
  viewEngine: {
    extName: '.hbs',
    partialsDir: 'some/path',
    layoutsDir: 'some/path',
    defaultLayout: '',
  },
  viewPath: 'some/path',
  extName: '.hbs',
};

transporter.use('compile', hbs(handlebarOptions));

erickjhorman commented 4 years ago

I managed to get my code working, posting in case it helps out. I had to add the partialsDir to my handlebarOptions where I didn't have the field before:

const handlebarOptions = {
  viewEngine: {
    extName: '.hbs',
    partialsDir: 'some/path',
    layoutsDir: 'some/path',
    defaultLayout: 'email.body.hbs',
  },
  viewPath: 'some/path',
  extName: '.hbs',
};

transporter.use('compile', hbs(handlebarOptions));

The partialsDir must have been an optional field at one point, but now seems to be required. Hope this helps.

Works for me too, using the partialDir. Thanks!

Hi can you show me what you put in the viewPath on your project?

LeTranAnhVu commented 4 years ago

I managed to get my code working, posting in case it helps out. I had to add the partialsDir to my handlebarOptions where I didn't have the field before:

const handlebarOptions = {
  viewEngine: {
    extName: '.hbs',
    partialsDir: 'some/path',
    layoutsDir: 'some/path',
    defaultLayout: 'email.body.hbs',
  },
  viewPath: 'some/path',
  extName: '.hbs',
};

transporter.use('compile', hbs(handlebarOptions));

The partialsDir must have been an optional field at one point, but now seems to be required. Hope this helps.

It works. But when I used different template to send email. The default template still used. My code:

var handlebarsOptions = {
    viewEngine: {
        extName: '.html',
        partialsDir: path.resolve('./views/templates/'),
        layoutsDir: path.resolve('./views/templates/'),
        defaultLayout: 'forgot-password-email.html',
    },
    viewPath: path.resolve('./views/templates/'),
    extName: '.html'
};
smtpTransport.use('compile', hbs(handlebarsOptions));
var data = {
                            from: process.env.EMAIL,
                            to: user.email,
                            template: 'reset-password-success-email',
                            subject: 'Password Reset Confirmation',
                            context: {
                                name: user.name
                            }
                        };
smtpTransport.sendMail(data);

Please help.

I had the same issue, just set the defaultLayout to an empty string and it'll depend on the template in the mailoptions:

const handlebarOptions = {
  viewEngine: {
    extName: '.hbs',
    partialsDir: 'some/path',
    layoutsDir: 'some/path',
    defaultLayout: '',
  },
  viewPath: 'some/path',
  extName: '.hbs',
};

transporter.use('compile', hbs(handlebarOptions));

It did work. Thanks