Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the package did not work on azure app service #677

Open
AriGabay opened this issue May 13, 2022 · 12 comments
Open

the package did not work on azure app service #677

AriGabay opened this issue May 13, 2022 · 12 comments

Comments

@AriGabay
Copy link

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] }

@MaurerKrisztian
Copy link

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'

code: https://github.com/MaurerKrisztian/template-api-tm

@MaurerKrisztian
Copy link

MaurerKrisztian commented May 21, 2022

@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
#612 (comment)
#612 (comment)
#35 (comment)

@chacabuk
Copy link

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",

@shreyasgombi
Copy link

Any luck? Facing a similar issue on my Azure App Service with Node 18 - LTS (18.16.0).

@MaurerKrisztian
Copy link

@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

@AriGabay
Copy link
Author

I'm creating HTML and converting it to pdf with jspdf,jspdf-autotable

@shreyasgombi
Copy link

@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?

@MaurerKrisztian
Copy link

@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
Copy link

shreyasgombi commented May 30, 2023

@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?

@AriGabay
Copy link
Author

The Docker file needs to be in the backend (App Service).
I think you should use jspdf,jspdf-autotable for creating a pdf file.

@shreyasgombi
Copy link

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. 😃 ❤️

@ATXadam
Copy link

ATXadam commented Jul 30, 2023

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants