Issue with jsPDF: Uncaught (in Promise) Error: Could not load dompurify: Error: cannot find module 'dompurify'

Viewed 3846

I'm using npm and parcel to build a web app. the dist files get copied to an apache2 server, (so not running under the node server) and when trying to generate a PDF using jsPDF I' getting this error:

Uncaught (in Promise) Error: Could not load dompurify: Error: cannot find module 'dompurify'

I think this is a problem with "sPDF will then dynamically load them (ie: dompurify and html2canvas) when required (using the respective module format, e.g. dynamic imports)." but I don't know how to work around it.

I have installed: npm install --save jspdf dompurify html2canvas

in my JS I "import jsPDF from 'jspdf';

    // download PDF doc
    let filename = 'pdf-' + $('#fh-date').val() + '-'
        + $('#fh-num').val() + '.pdf';
    let doc = new jsPDF();
    let specialElementHandlers = {
      '#editor': function (element, renderer) {
        return true;
      }
    };

    doc.html($('#fh-tmp').html(), {
        'width': 100, // max width of content of PDF
        'elementHandlers': specialElementHandlers,
        callback: function (doc) {
            doc.save(filename);
        },
    });

How do I solve this issue. Thanks?

1 Answers

I just ran accross this problem in my vue project, which i fixed by updating with "npm update".

Related