Error: write EPIPE with wkhtmltopdf + nodejs on Heroku
Error: write EPIPE with wkhtmltopdf + nodejs on Heroku
我使用 wkhtmltopdf 作为服务在 Web 应用程序中下载 pdf,在本地服务器中运行完美,但是当我在 heroku 上发送到生产环境时显示此错误:
Error: write EPIPE
at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:66:16)
Emitted 'error' event at:
at errorOrDestroy (internal/streams/destroy.js:98:12)
at onwriteError (_stream_writable.js:436:5)
at onwrite (_stream_writable.js:461:5)
at _destroy (internal/streams/destroy.js:40:7)
at Socket._destroy (net.js:618:3)
at Socket.destroy (internal/streams/destroy.js:32:8)
at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:67:12)
我使用的代码是这样的:
const htmlToPdf = async ({ body: { html } }, res) => {
const decodedHTml = decodeURI(html);
fs.readFile(path.join(__dirname, "", "style.css"), (err, data)=> {
if (error) throw error;
const style = `<style>${data}</style>`
wkhtmltopdf(style + decodedHTml, { pageSize: "A4" }).pipe(res);
});
};
错误是由于您没有安装 wkhtmltopdf 的命令行版本而导致的,因为这只是一个包装器。
检查可用版本:
我使用 wkhtmltopdf 作为服务在 Web 应用程序中下载 pdf,在本地服务器中运行完美,但是当我在 heroku 上发送到生产环境时显示此错误:
Error: write EPIPE
at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:66:16)
Emitted 'error' event at:
at errorOrDestroy (internal/streams/destroy.js:98:12)
at onwriteError (_stream_writable.js:436:5)
at onwrite (_stream_writable.js:461:5)
at _destroy (internal/streams/destroy.js:40:7)
at Socket._destroy (net.js:618:3)
at Socket.destroy (internal/streams/destroy.js:32:8)
at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:67:12)
我使用的代码是这样的:
const htmlToPdf = async ({ body: { html } }, res) => {
const decodedHTml = decodeURI(html);
fs.readFile(path.join(__dirname, "", "style.css"), (err, data)=> {
if (error) throw error;
const style = `<style>${data}</style>`
wkhtmltopdf(style + decodedHTml, { pageSize: "A4" }).pipe(res);
});
};
错误是由于您没有安装 wkhtmltopdf 的命令行版本而导致的,因为这只是一个包装器。
检查可用版本: