我使用这个节点库在nodejs端将html转换成pdf文件。转换后,它返回pdf缓冲区,我用来发送到邮件。
这是代码
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;
}这工作在本地系统,pdf被发送到邮件使用nodemailer。但是当我在heroku dyno上运行相同的代码时,它显示了
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)我如何解决这个问题,或任何其他库或方法?
发布于 2022-11-29 16:01:08
你好像错过了一个图书馆。
Aptfile的文件,其中包含您希望安装的Ubuntu包的名称。
libnss3
请注意,可能需要更多的包(见下文)。请注意,apt不执行依赖项解析。如果在这里添加依赖于其他包的包,则可能需要手动列出这些依赖项。
铬依赖性
运行Chromium或Chrome所需的确切依赖关系可能因版本而异,从Ubuntu版本到Ubuntu版本可能有所不同,但一个很好的起点是此依赖项列表来自“木偶词典”网站
ca-certificates
fonts-liberation
libappindicator3-1
libasound2
libatk-bridge2.0-0
libatk1.0-0
libc6
libcairo2
libcups2
libdbus-1-3
libexpat1
libfontconfig1
libgbm1
libgcc1
libglib2.0-0
libgtk-3-0
libnspr4
libnss3
libpango-1.0-0
libpangocairo-1.0-0
libstdc++6
libx11-6
libx11-xcb1
libxcb1
libxcomposite1
libxcursor1
libxdamage1
libxext6
libxfixes3
libxi6
libxrandr2
libxrender1
libxss1
libxtst6
lsb-release
wget
xdg-utils此列表可能会更改,不能保证完整。我建议您访问Puppeteer站点以获得更新的列表,如果您发现缺少更多的库,您可以按上面的方式一次添加它们。
https://stackoverflow.com/questions/74616716
复制相似问题