问题
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:-
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);
回答1:
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.
回答2:
I had a discussion with NPM creator and discussed that npm uses socket programming in it. So on further research found the Cloud Run doesn't support internal Socket calling, which is the correct reason this is not working.
来源:https://stackoverflow.com/questions/63412841/error-write-epipe-on-cloud-run-while-using-html-pdf-npm