Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
Tomdrouv1 opened this issue Feb 28, 2019 · 11 comments

Comments

@Tomdrouv1
Copy link

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
Copy link

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

@neon-sombrero
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

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
Copy link

1510143 commented Sep 20, 2019

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
Copy link

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
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests