write EPIPE error on generating html to pdf

Hi Team,

I'm trying to generate html to pdf using html-pdf npm. Please check below code
const invoicePath = path.resolve(path.join(__dirname, '../../../views/1.hbs'));
const templateHtml = fs.readFileSync(invoicePath, 'utf8');

const template = hb.compile(templateHtml);
const result = template({ data: body });
const milis = new Date().getTime();
pdf.create(result).toFile('receipt.pdf', function (err, res) {
if (err) {
console.log(err);
}
else {
console.log('res', res);
const data = fs.readFileSync(res.url).toString('base64');
}
});


getting error "Error: write EPIPE, err Error: spawn /usr/src/app/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs ENOENT"

can you please check guide us for the same?

Thanks is advance

0 11 7,246
11 REPLIES 11

Hello

Can you kindly advise if you are getting this error when working locally or when deploying into a Google Cloud Product. Are you using Docker when building your application?

Regards

It is working on local. Not working on Google Cloud Product. Yes, we are using Docker.

Hello

Thanks for confirming.

I believe that you are using the html-pdf [1] package for your project. It could be that you are missing a package on your Dockerfile, can you kindly check the following post which had a similar issue and error [2]. Lastly, since you are using a third party package, we provide best effort support and guide you to any external resources that would provide assistance [3]. 

Regards 

[1] https://www.npmjs.com/package/html-pdf

[2] https://stackoverflow.com/questions/63594283/nodejs-phantomjs-in-docker-error-spawn-enoent

[3] https://github.com/marcbachmann/node-html-pdf/issues

Thanks for the reply,

 

PhantomJs is deprecated so we can't use it and also checked https://github.com/marcbachmann/node-html-pdf/issues but not getting solution for google cloud.

Hello,

It could be related to the dependencies of the package and might have to contact the NPM package creator. Are you by chance deploying it on Cloud Run?

Regards

But it working on a local system. Yes, i tried with cloud function. 

Hello 

Thanks for confirming the product. 

Based on what I have researched, the package itself uses the phantomjs-prebuilt which will then install phantomjs for you based on your OS/architecture. Additionally it is important that the node_modules doesn't get copied over to the docker image but rather get installed on the docker file itself. On your .dockerignore file, can you try to add mode_modules/ to it.

Lastly, it seems that your post looks like a technical issue and considering the amount of information required to analyze it, it would be best to submit a tech case to the GCP support [1].

Regards

[1] https://cloud.google.com/support-hub

Hi,

Yes i tried with os.tmpdir but still getting same issue.. 

 

 

@irfanmodan i am having same issue , any workarounds ?
i tried suggested fixes , none of them works

@anas2612 still not getting a solution. Let me know if you found any.