1

I am trying to load html2pdf.js file from html2pdf.js external library as below :

import { LightningElement } from 'lwc';
import { loadStyle, loadScript } from 'lightning/platformResourceLoader';
import html2pdf from '@salesforce/resourceUrl/html2pdf';


export default class LwcToPDF extends LightningElement {

    renderedCallback() {
        loadScript(this, html2pdf).
            then(() => { console.log('loaded') }).
            catch(error => { console.error('Error :', error) })
    }
}

This leads to an error in console : lwcToPDF.js:4 Error : undefined

I have loaded the file as a static resource

static resource ss

What could be the possible reason behind this ? Is the library not compatible with LWCs or is there something else I am missing out on ?

1 Answer 1

1

Workers are not supported in LWC/Aura (see Locker API Viewer), because they are a security risk. As such, this lib won't be compatible unless you eliminate the possibility of loading the worker. Note that this only applies to Salesforce LWC, if you use a Visualforce or Lightning container, you'd be allowed to use this library, but you'd lose most of your ability to communicate with the rest of the Lightning Experience (which may be an acceptable tradeoff).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .