promise await throwing "RangeError: Maximum call stack size exceeded"

promise await throwing "RangeError: Maximum call stack size exceeded"

promise 正在等待抛出此错误 "RangeError: Maximum call stack size exceeded"

repo 是这个 one 我在 utils/email.js

上有一封电子邮件 class

这是我使用 pug 依赖项的 class 请看一下 pug.renderFile 如果我只在 h1 中发送一个字符串它工作正常但是对于哈巴狗它没有,我做错了什么哈巴狗文档就像我的代码一样,请事先帮助并感谢。

const nodemailer = require('nodemailer');
const pug = require('pug');
const { convert } = require('html-to-text');

module.exports = class Email {
  constructor(user, url) {
    this.to = user.email;
    this.firstName = user.name.split(' ')[0];
    this.url = url;
    this.from = `Cecilia Benitez <${process.env.EMAIL_FROM}>`;
  }

  newTransport() {
    /*if (process.env.NODE_ENV === 'production') {
      // Sendgrid
      return nodemailer.createTransport({
        service: 'SendGrid',
        auth: {
         user: process.env.SENDGRID_USERNAME,
          pass: process.env.SENDGRID_PASSWORD
        }
      });
    }*/

    return nodemailer.createTransport({
      host: process.env.EMAIL_HOST,
      port: process.env.EMAIL_PORT,
      auth: {
        user: process.env.EMAIL_USERNAME,
        pass: process.env.EMAIL_PASSWORD
      }
    });
  }

  // Send the actual email
  async send(template, subject) {
    // 1) Render HTML based on a pug template
    const html = pug.renderFile(`${__dirname}/../views/email/${template}.pug`, {
      firstName: this.firstName,
      url: this.url,
      subject
    });

    // 2) Define email options
    const mailOptions = {
      from: this.from,
      to: this.to,
      subject,
      html,
      text: convert(html, {
        wordwrap: 130
      })
    };

    // 3) Create a transport and send email
    return await this.newTransport().sendMail(mailOptions);
  }

  async sendWelcome() {
    return await this.send('welcome', 'Welcome to the Natours Family!');
  }

  async sendPasswordReset() {
    return await this.send(
      'passwordReset',
      'Your password reset token (valid for only 10 minutes)'
    );
  }
};

转到 views/email/baseEmail.pug 并将其改为

//- Email template adapted from https://github.com/leemunroe/responsive-html-email-template
//- Converted from HTML using https://html2pug.now.sh/
doctype html
html
  head
    meta(name='viewport', content='width=device-width')
    meta(http-equiv='Content-Type', content='text/html; charset=UTF-8')
    title= subject

    include _style
  body
    table.body(role='presentation', border='0', cellpadding='0', cellspacing='0')
      tbody
        tr
          td
          td.container
            .content
              // START CENTERED WHITE CONTAINER
              table.main(role='presentation')

                // START MAIN AREA
                tbody
                  tr
                    td.wrapper
                      table(role='presentation', border='0', cellpadding='0', cellspacing='0')
                        tbody
                          tr
                            td
                              // CONTENT
                              block content

              // START FOOTER
              .footer
                table(role='presentation', border='0', cellpadding='0', cellspacing='0')
                  tbody
                    tr
                      td.content-block
                        span.apple-link Natours Inc, 123 Nowhere Road, San Francisco CA 99999
                        br
                        |  Don't like these emails? 
                        a(href='#') Unsubscribe
          //- td