yads / nodemailer-express-handlebars

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

The “path” argument must be of type string. Received undefined #47

Open DoneDeal0 opened 3 years ago

DoneDeal0 commented 3 years ago

When trying to send an email, the server crashes with this error:

err checkout TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined at new NodeError (node:internal/errors:329:5) at validateString (node:internal/validators:129:11) at Object.join (node:path:1081:7) at TemplateGenerator.render (/Users/myname/Desktop/Code/myapp/server/node_modules/nodemailer-express-handlebars/lib/generator.js:19:29) at /Users/myname/Desktop/Code/myapp/server/node_modules/nodemailer-express-handlebars/lib/index.js:9:19

The code is:

require("dotenv").config();
import nodemailer from "nodemailer";
import hbs from "nodemailer-express-handlebars";

const transporter = nodemailer.createTransport({
  service: "gmail",
  auth: {
    user: process.env.NODEMAILER_EMAIL,
    pass: process.env.NODEMAILER_PASSWORD,
  },
  tls: {
    rejectUnauthorized: false,
  },
});

transporter.use(
  "compile",
  hbs({
    viewEngine: "express-handlebars",
    viewPaths: "../mails/",
    extName: ".hbs",
  })
);

export class MailControler {
  static confirmSignup(
    { email, username },
    price: string
  ) {
    return transporter.sendMail({
      from: appMail,
      to: email,
      subject: "Hello",
      template: "confirmSignup",
      context: {
        username
      },
    });
  }
}

The route is working, the transporter is defined (I can log it in the terminal with the correct informations), the express-handlebars context is defined (I can also log the variable username), I can also log the process.env parts.

The structure is:

So there is no directory error here.

Where is this undefined path argument?

yads commented 3 years ago

The argument to the plugin is viewPath not viewPaths.

AprendiendoconGuillermo commented 2 years ago

I use viewPath , but i have the same error, why...?

yads commented 2 years ago

I can't help you troubleshoot this with no info.