I and several others have been getting the following error when testing custom lightning web components in a scratch org:
"The first parameter of loadScript() and loadStyle() must be an LWC component."
While debugging, it is because platformResourceLoader.js
(which contains loadScript()
) first null-checks cmp.template.host.ownerDocument
where in my case, ownerDocument
is undefined.
This is a documented Salesforce issue and they provide the following workaround:
Current work around is to create another wrapper lwc custom component and use the custom component with platformResourceLoader in the wrapper.
e.g --- c-lwc-wrapper --
<template> <c-lwc-loader></c-lwc-loader> </template>
where c-lwc-loader uses
import { loadStyle, loadScript } from 'lightning/platformResourceLoader';`
Can someone explain to me in more detail what this means? Am I supposed to create an entirely new LWC and nest my original one inside it? The wording of the sentence and my relative unfamiliarity with HTML/JS are causing quite the headache.