I am using this html-pdf-node library to convert html to pdf file in nodejs side. After converting it returns the pdf buffer, that i use to send to mail.
Here is the code
const file = { content: attachementPdfContentString };
return htmlToPdf.generatePdf(file, options).then(pdfBuffer => {
try {
return this.sendMail({
to: hotelEmail,
subject: "Dashback Invoice",
body: `Hi `,
attachments: [
{
filename: 'invoice.pdf',
content: Buffer.from(pdfBuffer, 'utf-8')
}
]
});
} catch (err) {
console.error("Unable to send mail for hotel invitation", JSON.stringify(invoice));
throw err;
}
this works on local system, pdf is getting sent to mail using nodemailer. But when I run the same code on heroku dyno, it shows
2022-11-29T15:43:13.506732+00:00 app[web.1]: Error: Failed to launch the browser process!
2022-11-29T15:43:13.506734+00:00 app[web.1]: /app/node_modules/puppeteer/.local-chromium/linux-901912/chrome-linux/chrome: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory
2022-11-29T15:43:13.506734+00:00 app[web.1]:
2022-11-29T15:43:13.506734+00:00 app[web.1]:
2022-11-29T15:43:13.506735+00:00 app[web.1]: TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
2022-11-29T15:43:13.506735+00:00 app[web.1]:
2022-11-29T15:43:13.506735+00:00 app[web.1]: at onClose (/app/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:197:20)
2022-11-29T15:43:13.506736+00:00 app[web.1]: at Interface.<anonymous> (/app/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:187:68)
2022-11-29T15:43:13.506736+00:00 app[web.1]: at Interface.emit (node:events:525:35)
2022-11-29T15:43:13.506737+00:00 app[web.1]: at Interface.close (node:internal/readline/interface:536:10)
2022-11-29T15:43:13.506738+00:00 app[web.1]: at Socket.onend (node:internal/readline/interface:262:10)
2022-11-29T15:43:13.506738+00:00 app[web.1]: at Socket.emit (node:events:525:35)
2022-11-29T15:43:13.506738+00:00 app[web.1]: at endReadableNT (node:internal/streams/readable:1359:12)
2022-11-29T15:43:13.506739+00:00 app[web.1]: at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
How can i solve this, or any other library or way?
It looks like you're missing a library.
libnss3.so
is found in thelibnss3
Ubuntu package. You can install it using the apt buildpack:Add the apt buildpack as your first buildpack, e.g. by running
Create a file called
Aptfile
in the root directory of your project that contains the names of the Ubuntu packages you wish to install, e.g.Note that additional packages may be required (see below).
Commit and redeploy.
Note that the apt buildpack does not do dependency resolution. If you add packages here that depend on other packages, you may need to manually list those dependencies.
Chromium dependencies
The exact dependencies required to run Chromium or Chrome may vary from release to release and from Ubuntu version to Ubuntu version, but a good starting point is this list of dependencies from the Puppeteer website:
This list is subject to change and not guaranteed to be complete. I suggest you visit the Puppeteer site for an updated list, and if you find that additional libraries are missing you can add them one at a time as above.