'Error while sending PDF as an email attachment - Failed to launch the browser process

We're facing an issue while sending an attachment to a mail. Our scenario is something like, we're having a button "Send to My Email" which collects the logged-in user email and sends the filled form as a pdf to an email attachment. Everything is working fine on our local machine, but we're getting an error on the live testing site.

Our backend expressjs controller code:

const sendFormToEmail = async (req, res, next) => {
  try {
    const { formDetails } = req.body;

    const to = formDetails?.email;
    const from = "Our App Name here";
    const subject = `Form Attachment`;
    const html = emailTemplate({ formDetails });

    let options = { format: "A4" };
    let file = { content: html };
    const pdfBuffer = await html_to_pdf.generatePdf(file, options);

    await sendEmail({
      to,
      subject,
      from,
      html,
      pdfBuffer,
      filename: "form.pdf",
    });

    res.status(200).send({
      status: true,
      message: "Form sent to email successfully",
    });
  } catch (err) {
    console.log("Error is ", err);
    res.status(500).send({
      status: false,
      message: "Failed to send Form on an email",
    });
  }
};

sendEmail function code:

async function sendEmail({
  to,
  from,
  subject,
  text,
  html,
  pdfBuffer,
  filename,
}) {
  try {
    const sendEmailResponse = await SENDGRID.send({
      from,
      to,
      text,
      html,
      subject,
      attachments: [
        {
          content: pdfBuffer.toString("base64"),
          filename: filename,
          type: "application/pdf",
          disposition: "attachment",
        },
      ],
    });
    console.log("EMAIL_SUCCESSFULLY_SEND: ", sendEmailResponse);
    return true;
  } catch (err) {
    console.log(err.response.body.errors);
    throw err;
  }
}

The error we're facing:

Error is Error: Failed to launch the browser process! /root/application-name/node_modules/html-pdf-node/node_modules/puppeteer/.local-chromium/linux-901912/chrome-linux/chrome: error while loading shared libraries: libatk-1.0.so.0: cannot open shared object file: No such file or directory

Please, help us in getting rid of this issue



Solution 1:[1]

So, basically, I found the solution for this here.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Mohsin