javascriptnode.jspdfherokuhtml-pdf

Error on nodejs app running on heroku. (html-pdf)


I am using library html-pdf to render pdf and then send the file with email. It works like a charm on localhost

pdf.create(html, {format: 'A4'}).toFile(`./public/invoices/${order.id}.pdf`, (err, res) => {
            if (err) return console.log(err);
        });

Currently I'm hosting the nodejs on Heroku. It works fine until the pdf.create() executes. Getting this error:

2022-08-25T21:32:13.925568+00:00 app[web.1]: Auto configuration failed
2022-08-25T21:32:13.925570+00:00 app[web.1]: 139861897091008:error:25066067:DSO support routines:DLFCN_LOAD:could not load the shared library:dso_dlfcn.c:185:filename(libproviders.so): libproviders.so: cannot open shared object file: No such file or directory
2022-08-25T21:32:13.925571+00:00 app[web.1]: 139861897091008:error:25070067:DSO support routines:DSO_load:could not load the shared library:dso_lib.c:244:
2022-08-25T21:32:13.925572+00:00 app[web.1]: 139861897091008:error:0E07506E:configuration file routines:MODULE_LOAD_DSO:error loading dso:conf_mod.c:285:module=providers, path=providers
2022-08-25T21:32:13.925573+00:00 app[web.1]: 139861897091008:error:0E076071:configuration file routines:MODULE_RUN:unknown module name:conf_mod.c:222:module=providers
2022-08-25T21:32:13.925574+00:00 app[web.1]: 
2022-08-25T21:32:13.925575+00:00 app[web.1]:     at ChildProcess.respond (/app/node_modules/html-pdf/lib/pdf.js:134:17)
2022-08-25T21:32:13.925576+00:00 app[web.1]:     at ChildProcess.emit (node:events:513:28)
2022-08-25T21:32:13.925576+00:00 app[web.1]:     at ChildProcess.emit (node:domain:489:12)
2022-08-25T21:32:13.925577+00:00 app[web.1]:     at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)

I think the problem is in some of the html-pdf dependencies, like phantomjs. Would be glad if somebody could help me, or if someone knows about better html-pdf solution.


Solution

  • I actually found solution.

    If anyone else wondering, just add

    childProcessOptions: { env: { OPENSSL_CONF: '/dev/null' }
    

    to options.

    So it will look something like this

    pdf.create(html, {/* ... */ childProcessOptions: { env: { OPENSSL_CONF: '/dev/null' }}).toFile(`./public/invoices/${order.id}.pdf`, (err, res) => {
                if (err) return console.log(err);
            });