ericf / express-handlebars

A Handlebars view engine for Express which doesn't suck.
BSD 3-Clause "New" or "Revised" License
2.31k stars 384 forks source link

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

Closed DoneDeal0 closed 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?

EDIT: Sorry, I wanted to write in nodemailer-express-handlebar repo. I close this issue (solution are welcome though!)