Open AriGabay opened 2 years ago
Hi. Locally working fine but I got the same error when the code is running on a Linode server. (and the server crashes somehow after pdf generate error 502 Bad Gateway)
events.js:377
throw er; // Unhandled 'error' event
^
Error: write EPIPE
at afterWriteDispatched (internal/stream_base_commons.js:156:25)
at writeGeneric (internal/stream_base_commons.js:147:3)
at Socket._writeGeneric (net.js:798:11)
at Socket._write (net.js:810:8)
at writeOrBuffer (internal/streams/writable.js:358:12)
at Socket.Writable.write (internal/streams/writable.js:303:10)
at PDF.PdfExec [as exec] (/opt/app/node_modules/html-pdf/lib/pdf.js:156:15)
at PDF.PdfToBuffer [as toBuffer] (/opt/app/node_modules/html-pdf/lib/pdf.js:46:8)
at /opt/app/dist/template/services/PdfService.js:8:30
at new Promise (<anonymous>)
Emitted 'error' event on Socket instance at:
at emitErrorNT (internal/streams/destroy.js:106:8)
at emitErrorCloseNT (internal/streams/destroy.js:74:3)
at processTicksAndRejections (internal/process/task_queues.js:82:21) {
errno: -32,
code: 'EPIPE',
syscall: 'write'
@AriGabay I found some solution: If I understand correctly the problem is this package need fonts and try to reach phantomJs but not exist in the environment https://github.com/marcbachmann/node-html-pdf/issues/612#issuecomment-798835694 https://github.com/marcbachmann/node-html-pdf/issues/612#issuecomment-854249720 https://github.com/marcbachmann/node-html-pdf/issues/35#issuecomment-155144094
Exactly same issue... I cant solve it... I try to add config option in many ways this no luck...
phantomPath: "../../../node_modules/phantomjs-prebuilt/bin/phantomjs",
phantomPath: "../../../node_modules/phantomjs/bin/phantomjs",
phantomPath: "./node_modules/phantomjs/bin/phantomjs",
Any luck? Facing a similar issue on my Azure App Service with Node 18 - LTS (18.16.0).
@shreyasgombi I think I managed to solve it, but it was a while ago, I don't quite remember what exactly I tried. I hope this Dockerfile helps https://github.com/MaurerKrisztian/template-api-tm/blob/main/Dockerfile
I'm creating HTML and converting it to pdf with jspdf,jspdf-autotable
@shreyasgombi I think I managed to solve it, but it was a while ago, I don't quite remember what exactly I tried. I hope this Dockerfile helps https://github.com/MaurerKrisztian/template-api-tm/blob/main/Dockerfile
Any idea how to use the Docker file on Azure App Service (Web App)? I'm a newbie to Azure app service. Should I include it in my app project and build?
@shreyasgombi I think I managed to solve it, but it was a while ago, I don't quite remember what exactly I tried. I hope this Dockerfile helps https://github.com/MaurerKrisztian/template-api-tm/blob/main/Dockerfile
Any idea how to use the Docker file on Azure App Service (Web App)? I'm a newbie to Azure app service. Should I include it in my app project and build?
Idk, I don't use Azure.
@shreyasgombi I think I managed to solve it, but it was a while ago, I don't quite remember what exactly I tried. I hope this Dockerfile helps https://github.com/MaurerKrisztian/template-api-tm/blob/main/Dockerfile
Any idea how to use the Docker file on Azure App Service (Web App)? I'm a newbie to Azure app service. Should I include it in my app project and build?
Idk, I don't use Azure.
Ah, ok. Got it. May be @AriGabay can suggest?
The Docker file needs to be in the backend (App Service). I think you should use jspdf,jspdf-autotable for creating a pdf file.
Ok,
So adding this bash -c "apt-get install libfontconfig -y && /opt/startup/init_container.sh"
to the Startup Command did the job!
Thanks for the help though. 😃 ❤️
This can be resolved in Azure by going to the Web App container in portal.azure.com, and under Settings -> Configuration -> General Settings -> Startup Command change to, for example,
apt install libfontconfig -y && OPENSSL_CONF=/etc/ssl/ npm start
This will add the correct font library and fix phantomjs's SSL error that you'd get after that's resolved.
Working Thanks
Hi everyone, I ran this function on the azure app service and got this error.
function :
const bufferPdf = async (html, options) => { try { return new Promise((resolve, reject) => { pdf.create(html, options).toBuffer(function (err, buffer) { if (err) { return reject(err); } resolve(buffer); }); }); } catch (e) { console.log('ERROR [bufferPdf]:', e); } };
the Error :
2022-05-13T19:14:38.225244279Z: [ERROR] events.js:377 2022-05-13T19:14:38.225273879Z: [ERROR] throw er; // Unhandled 'error' event 2022-05-13T19:14:38.225279879Z: [ERROR] ^ 2022-05-13T19:14:38.225283879Z: [ERROR] 2022-05-13T19:14:38.225287679Z: [ERROR] Error: write EPIPE 2022-05-13T19:14:38.225291579Z: [ERROR] at afterWriteDispatched (internal/stream_base_commons.js:156:25) 2022-05-13T19:14:38.225303979Z: [ERROR] at writeGeneric (internal/stream_base_commons.js:147:3) 2022-05-13T19:14:38.225309279Z: [ERROR] at Socket._writeGeneric (net.js:787:11) 2022-05-13T19:14:38.225313379Z: [ERROR] at Socket._write (net.js:799:8) 2022-05-13T19:14:38.225317179Z: [ERROR] at writeOrBuffer (internal/streams/writable.js:358:12) 2022-05-13T19:14:38.225321079Z: [ERROR] at Socket.Writable.write (internal/streams/writable.js:303:10) 2022-05-13T19:14:38.225325179Z: [ERROR] at PDF.PdfExec [as exec] (/home/site/wwwroot/node_modules/html-pdf/lib/pdf.js:156:15) 2022-05-13T19:14:38.225329079Z: [ERROR] at PDF.PdfToBuffer [as toBuffer] (/home/site/wwwroot/node_modules/html-pdf/lib/pdf.js:46:8) 2022-05-13T19:14:38.225332979Z: [ERROR] at /home/site/wwwroot/services/email.service.js:22:33 2022-05-13T19:14:38.225336679Z: [ERROR] at new Promise ()
2022-05-13T19:14:38.225341079Z: [ERROR] Emitted 'error' event on Socket instance at:
2022-05-13T19:14:38.225344879Z: [ERROR] at emitErrorNT (internal/streams/destroy.js:106:8)
2022-05-13T19:14:38.225348579Z: [ERROR] at emitErrorCloseNT (internal/streams/destroy.js:74:3)
2022-05-13T19:14:38.225352278Z: [ERROR] at processTicksAndRejections (internal/process/task_queues.js:82:21) {
2022-05-13T19:14:38.225356078Z: [ERROR] errno: -32,
2022-05-13T19:14:38.225369278Z: [ERROR] code: 'EPIPE',
2022-05-13T19:14:38.225373078Z: [ERROR] syscall: 'write'
2022-05-13T19:14:38.225376478Z: [ERROR] }