简体   繁体   English

错误:在使用 html-pdf NPM 时在 Cloud Run 上编写 EPIPE

[英]Error: write EPIPE on Cloud Run while using html-pdf NPM

Here I was trying to convert HTML to PDF and used html-pdf npm ( https://www.npmjs.com/package/html-pdf )). Here I was trying to convert HTML to PDF and used html-pdf npm ( https://www.npmjs.com/package/html-pdf )). The code was running fine on local and got an issue over google cloud run.该代码在本地运行良好,但在谷歌云运行时出现问题。

Error: write EPIPE at afterWriteDispatched (internal/stream_base_commons.js:154:25) at writeGeneric (internal/stream_base_commons.js:145:3) at Socket._writeGeneric (net.js:786:11) at Socket._write (net.js:798:8) at doWrite (_stream_writable.js:403:12) at writeOrBuffer (_stream_writable.js:387:5) at Socket.Writable.write (_stream_writable.js:318:11) at PDF.PdfExec [as exec] (/usr/src/app/node_modules/html-pdf/lib/pdf.js:141:15) at PDF.PdfToBuffer [as toBuffer] (/usr/src/app/node_modules/html-pdf/lib/pdf.js:44:8) at utilities.createPDF (/usr/src/app/routes/lib/utilities.js:810:31)

Emitted 'error' event on Socket instance at:

 at errorOrDestroy (internal/streams/destroy.js:108:12)

 at onwriteError (_stream_writable.js:418:5)

 at onwrite (_stream_writable.js:445:5)

 at internal/streams/destroy.js:50:7

 at Socket._destroy (net.js:679:5)

 at Socket.destroy (internal/streams/destroy.js:38:8)

 at afterWriteDispatched (internal/stream_base_commons.js:154:17)

 at writeGeneric (internal/stream_base_commons.js:145:3)

 at Socket._writeGeneric (net.js:786:11)

 at Socket._write (net.js:798:8) {

 errno: 'EPIPE',

 code: 'EPIPE',

 syscall: 'write'

This the JS code used, error occurred on pdf.create function:-这是使用的 JS 代码,在pdf.create function 上发生错误:-

var pdf = require('html-pdf');
var html = <HTML code>;
var options = { 
    format: 'A4',
    border: {
        "top": "20px",            
        "right": "15px",
        "bottom": "15px",
        "left": "12.5px"
      },
 };
 
pdf.create(html, options).toBuffer(function(err, buffer){
  console.log('This is a buffer:', Buffer.isBuffer(buffer));
    console.log(buffer);

It looks like Cloud Run does not support HTML streaming , which is what I interpret the code to be doing in the error message, so it looks like that specific code might not be supported.看起来 Cloud Run不支持 HTML 流式传输,这是我在错误消息中解释要执行的代码,因此看起来可能不支持特定代码。

I had a discussion with NPM creator and discussed that npm uses socket programming in it.我与 NPM 创建者进行了讨论,并讨论了 npm 在其中使用套接字编程。 So on further research found the Cloud Run doesn't support internal Socket calling, which is the correct reason this is not working.所以进一步研究发现 Cloud Run 不支持内部 Socket 调用,这是它不起作用的正确原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM