marcbachmann / node-html-pdf

This repo isn't maintained anymore as phantomjs got dreprecated a long time ago. Please migrate to headless chrome/puppeteer.
MIT License
3.56k stars 545 forks source link

ReferenceError : __dirname is not defined #651

Open praveenkpatare opened 2 years ago

praveenkpatare commented 2 years ago

I am working on a project in Svelte Kit where i have to convert an invoice in the form of an html string in pdf byte array.

I am using the html-pdf library to generate the pdf byte array from html string, however i am getting this error -

pdf.js:32 Uncaught (in promise) ReferenceError: __dirname is not defined at new PDF (pdf.js:32) at Object.createPdf [as create] (index.js:10) at sttRanges.svelte? [sm]:194 at new Promise () at returnHtmlAsPdf (sttRanges.svelte? [sm]:192) at generateStmts (sttRanges.svelte? [sm]:185) at sttRanges.svelte? [sm]:75 at async HTMLButtonElement.getStmtData (sttRanges.svelte? [sm]:58)

Below is the code snippet -

async function returnHtmlAsPdf(html) { return new Promise(async (resolve, reject) => { await pdf.create(html, options).toBuffer(function(err, buffer){ if(err){ console.log(err); reject(err); } resolve(buffer); }) });

PLease advise how to resolve this or is there any work around.