yads / nodemailer-express-handlebars

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

Can't set relative viewPath to one folder up #25

Closed TidyIQ closed 5 years ago

TidyIQ commented 5 years ago

My folder structure:

var/www/app/
  - email_templates/
    - partials/
    - layouts/
      - user_email_confirmation.handlebars
  - dist/
    - emails.js

In dist/emails.js, I'm trying to set the viewPath to email_templates/layout.

If I use viewPath: "../email_templates/layouts" then I get the error:

Error: ENOENT: no such file or directory, open '/var/www/email_templates/layouts/user_email_confirmation.handlebars'

If I use viewPath: "/email_templates/layouts" then I get the error:

Error: ENOENT: no such file or directory, open '/email_templates/layouts/user_email_confirmation.handlebars'

If I use viewPath: "./email_templates/layouts" or viewPath: "email_templates/layouts" then I get the error:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined

It doesn't seem possible to simply set the viewPath as a relative path to one folder up from the parent. Is that correct?

TidyIQ commented 5 years ago

For some reason I can't edit this post... I was trying to edit the name and description as it looks like the issue is that you can't set viewPath at all if you have a folder that contains periods in it.

In development my root folder is app/. In production it is var/www/api.my-domain.com/.

If I use viewPath: "/var/www/api.my-domain.com/email_templates/layouts" or viewPath: "../api.my-domain.com/email_templates/layouts" then I get the same error as before:

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined.
at validateString (internal/validators.js:125:11)
    at Object.resolve (path.js:1080:7)
    at ExpressHandlebars._resolveLayoutPath (/var/www/api.my-domain.com/node_modules/express-handlebars/lib/express-handlebars.js:342:17)
    at ExpressHandlebars.<anonymous> (/var/www/api.my-domain.com/node_modules/express-handlebars/lib/express-handlebars.js:223:35)

No matter what I try, I can't set the viewPath. Neither absolute or relative paths work.

hzburki commented 5 years ago

I have the same problem.

Node Version: v10.15.1 NPM Version: 6.9.0

Error Stack

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at assertPath (path.js:39:11)
    at Object.resolve (path.js:1085:7)
    at ExpressHandlebars._resolveLayoutPath (/Applications/MAMP/htdocs/numu/node-api/node_modules/express-handlebars/lib/express-handlebars.js:342:17)
    at ExpressHandlebars.<anonymous> (/Applications/MAMP/htdocs/numu/node-api/node_modules/express-handlebars/lib/express-handlebars.js:223:35)

Express Handlebars Config Object

const mailgunHandlebars = {
  viewEngine: handlebarsEngine,
  viewPath: path.resolve(__dirname, "../views/emails/"),
  extName: ".hbs"
};

logging path.resolve(__dirname, "../views/emails/") returns /Applications/MAMP/htdocs/project_name/src/views/emails. All email templates are present in this directory

yads commented 5 years ago

Looks like a duplicate of #26