I am trying to use PapaParse (a Javascript CSV analyzer library) in a Lightning Web Component. A lightning modal hosts the tool. Although I have seen examples of doing so in the past, I have been having a lot of trouble getting the base Papa object to instantiate. It is visible in Chrome devtools (i.e. I can see Papa and this.Papa, and Papa.LocalChunkSize) but these are all undefined in the LWC itself. Has anybody successfully implemented recently? I am worried that PapaParse may no longer be compatible due to security strengthening in Salesforce Winter '23 release.
I also pasted papaparse.js into LWS Security Console and found these Linting Results. errorMessages: 1, warningMessages: 2 38:2 - error: Definition for rule 'func-name' was not found. 668:4 - warning: {XMLHttpRequest|Window}.prototype.open is distorted by Lightning Web Security. 1141:5 - warning: window.setTimeout is distorted by Lightning Web Security. The func-name refers to this line which doesn't seem like a big deal. // eslint-disable-next-line func-name
My implementation method is: Create a papaparse folder in the vscode project's staticresources folder. In it put papaparse.js. At same level as folder, create a resource-meta.xml. Push to my sandbox with sfdx force:source:deploy -p force-app/main/default/staticresources
In LWC:
...
parserLibraryFile = 'papaparse.js';
...
renderedCallback() {
if (!this.parserReady) {
loadScript(this, PARSER + '/' + this.parserLibraryFile)
.then(() => {
this.parserReady = true;
})
.catch(error =>
console.log('ERROR loading PapaParse parser '+error)
);
}
}
In handleMonitorButtonClick() :
if (this.parserReady) {
console.log('Papa bare obj:');
console.log(Papa);
console.log('Papa this obj:');
console.log(this.Papa);
console.log('Papa window obj:');
console.log(window.Papa);
console.log('papa chunksize is ');
console.log(this.Papa.LocalChunkSize);
}
These are defined in Chrome devtools but not when I check in LWC.. then they are defined as soon as an error is thrown (typically "Cannot read properties of undefined" when trying to get LocalChunkSize.
I am running with Lightning Web Security (LWS) disabled in Session Settings, though I think it may be forced anyway with this release. Theoretically I could downgrade the API to around 38 to turn that off... Hope someone has some good news and a working example I could try.