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

Path must be a string. Received undefined #26

Open
johnlimed opened this issue Jun 6, 2019 · 2 comments
Open

Path must be a string. Received undefined #26

johnlimed opened this issue Jun 6, 2019 · 2 comments

Comments

@johnlimed
Copy link

Stacktrace:
at assertPath (path.js:28:11)
at Object.resolve (path.js:1171:7)
ExpressHandlebars._resolveLayoutPath

This issue is caused by the dependency: ExpressHandlebars.

Underlying issue is because of a change in ExpressHandlebars, it will use defaultLayout='main' no matter what, as such it expects the layoutDir to be a string however for users who do not use a layout, like in my case, it will throw this error 'Path must be a string ...'

Just putting this issue here so that people who might have this issue can know a quick fix:

Whenever you generate your mailOptions, set your context.layout=false.
This would override the defaultLayout in ExpressHandlebars to be false and not produce this bug.

The real fix would have to be implemented by ExpressHandlebars which there are requests to remove the defaultLayout.

if a patch wants to be made in nodemailer-express-handlebars, I was thinking a quick fix could be adding the following to the render function:

TemplateGenerator.prototype.render = function render(mail, cb) {
    if (mail.data.html) return cb();

    var templatePath = path.join(this.viewPath, mail.data.template + this.extName);
    const { layout } = mail.data.context;
    if (!layout) mail.data.context.layout = false;
    this.viewEngine.renderView(templatePath, mail.data.context, function(err, body) {
        if (err) return cb(err);

        mail.data.html = body;
        cb();
    });
};
@hzburki
Copy link

hzburki commented Jun 13, 2019

I have the same issue here

@nbrookie
Copy link

nbrookie commented Jun 17, 2019

@johnlimed @hzburki I ran into a similar issue and fixed it by adding defaultLayout: false to handlebars options:

  const options = {
    viewEngine: {
      extName: ".hbs",
      partialsDir: path.resolve(__dirname, "templates"),
      defaultLayout: false        // <-----   added this
    },
    viewPath: path.resolve(__dirname, "templates"),
    extName: ".hbs"
  };

  this.transporter.use("compile", hbs(options));

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

3 participants