【问题标题】:Heroku PDFTK throwing vague EPIPE and EACCES errorHeroku PDFTK 抛出模糊的 EPIPE 和 EACCES 错误
【发布时间】:2020-01-16 18:06:21
【问题描述】:

我在运行相当基本的节点 api 的 heroku 爱好 web dyno 上有一个应用程序。 我们有一系列 pdf 附加到 puppeteer 生成的 pdf 上。 我的代码在本地(Windows)运行时有效,但当我部署到我的生产 heroku 实例时它也有效。 这是有问题的代码:

try{

//If there are pdfs to attach to the end of the file, we do it here.
let fileList = [];
console.log('*');
for (const file of pdfFileNameList) {
    fileList.push("./pdfs/" + file.pdf);
}

console.log('**');
//Spawn a child process to run pdftk to merge the pdfs.
let execer = require('child_process').spawn;
let child;
let args = ['-'].concat(fileList).concat(['cat', 'output', '-']);
console.log(args);

console.log('***');
child = execer('pdftk', args, {
    encoding: 'binary',
    stdio: ['pipe']
});

//Write the file PDF binary data to the child process' stdin.
//It will combine that with the list of pdfs specified in fileList.
console.log('****');
child.stdin.write(data);
console.log('*****');
child.stdin.end();
console.log('******');

let bufferArray = [];
//shove the data from the child process into my bufferArray as it comes in.
child.stdout.on('data', function (pdfdata) {
    bufferArray.push(new Buffer(pdfdata, 'binary'));
});
console.log('*******');
//When the process is done, send the concatted pdf to the user.
child.on('close', function () {
    res.header('Content-Type', "application/pdf");
    res.send(Buffer.concat(bufferArray));
});
console.log('********');

} catch (err) {
    console.error(err);
}

这是导致的错误集:

2020-01-16T18:02:37.830775+00:00 app[web.1]: *
2020-01-16T18:02:38.356266+00:00 app[web.1]: **
2020-01-16T18:02:38.358310+00:00 app[web.1]: [ '-', '/app/pdfs/Example.pdf', 'cat', 'output', '-' ]
2020-01-16T18:02:38.358371+00:00 app[web.1]: ***
2020-01-16T18:02:38.373374+00:00 app[web.1]: ****
2020-01-16T18:02:38.375832+00:00 app[web.1]: Error: write EPIPE
2020-01-16T18:02:38.375836+00:00 app[web.1]: at afterWriteDispatched (internal/stream_base_commons.js:149:25)
2020-01-16T18:02:38.375838+00:00 app[web.1]: at writeGeneric (internal/stream_base_commons.js:140:3)
2020-01-16T18:02:38.375843+00:00 app[web.1]: at Socket._writeGeneric (net.js:776:11)
2020-01-16T18:02:38.375845+00:00 app[web.1]: at Socket._write (net.js:788:8)
2020-01-16T18:02:38.375847+00:00 app[web.1]: at doWrite (_stream_writable.js:435:12)
2020-01-16T18:02:38.375849+00:00 app[web.1]: at writeOrBuffer (_stream_writable.js:419:5)
2020-01-16T18:02:38.375851+00:00 app[web.1]: at Socket.Writable.write (_stream_writable.js:309:11)
2020-01-16T18:02:38.375853+00:00 app[web.1]: at Object.returnReport (/app/models/report_functions.js:245:33) {
2020-01-16T18:02:38.375855+00:00 app[web.1]: errno: 'EPIPE',
2020-01-16T18:02:38.375857+00:00 app[web.1]: code: 'EPIPE',
2020-01-16T18:02:38.375859+00:00 app[web.1]: syscall: 'write'
2020-01-16T18:02:38.375861+00:00 app[web.1]: }
2020-01-16T18:02:38.378481+00:00 app[web.1]: events.js:200
2020-01-16T18:02:38.378484+00:00 app[web.1]: throw er; // Unhandled 'error' event
2020-01-16T18:02:38.378486+00:00 app[web.1]: ^
2020-01-16T18:02:38.378488+00:00 app[web.1]:
2020-01-16T18:02:38.378490+00:00 app[web.1]: Error: spawn pdftk EACCES
2020-01-16T18:02:38.378492+00:00 app[web.1]: at Process.ChildProcess._handle.onexit (internal/child_process.js:264:19)
2020-01-16T18:02:38.378495+00:00 app[web.1]: at onErrorNT (internal/child_process.js:456:16)
2020-01-16T18:02:38.378497+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:81:21)
2020-01-16T18:02:38.378499+00:00 app[web.1]: Emitted 'error' event on ChildProcess instance at:
2020-01-16T18:02:38.378501+00:00 app[web.1]: at Process.ChildProcess._handle.onexit (internal/child_process.js:270:12)
2020-01-16T18:02:38.378503+00:00 app[web.1]: at onErrorNT (internal/child_process.js:456:16)
2020-01-16T18:02:38.378505+00:00 app[web.1]: at processTicksAndRejections (internal/process/task_queues.js:81:21) {
2020-01-16T18:02:38.378507+00:00 app[web.1]: errno: 'EACCES',
2020-01-16T18:02:38.378509+00:00 app[web.1]: code: 'EACCES',
2020-01-16T18:02:38.378511+00:00 app[web.1]: syscall: 'spawn pdftk',
2020-01-16T18:02:38.378513+00:00 app[web.1]: path: 'pdftk',
2020-01-16T18:02:38.378515+00:00 app[web.1]: spawnargs: [ '-', '/app/pdfs/Example.pdf', 'cat', 'output', '-' ]
2020-01-16T18:02:38.378517+00:00 app[web.1]: }

【问题讨论】:

标签: node.js heroku pdftk


【解决方案1】:

如果其他人遇到此错误“错误:生成 pdftk ENOENT”。

这个错误很可能是因为 Heroku 在您的系统上找不到“PdfTK”。

将这个 buildpack 添加到 Heroku 为我解决了这个问题: 'https://github.com/fxtentacle/heroku-pdftk-buildpack.git' (我在 'heroku/nodejs' buldback 下添加了它)

【讨论】:

  • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-17
  • 1970-01-01
  • 2021-03-04
  • 1970-01-01
  • 2020-08-18
  • 2017-06-21
相关资源
最近更新 更多