TL;DR;
As of my experience, the most common reason why [NoErrorObjectAvailable] Script error
appears is when because a custom event is handled by a ghost method, meaning a method that does not exist on the JS controller.
For example, oncustomevent={ghostMethod}
, where ghostMethod
does not exist in the JS controller.
Long version
Let's say we have a child component like the following:
childComp.html
<template>
<lightning-button label="Notify Parent Comp" onclick={notifyParent}></lightning-button>
</template>
childComp.js
import { LightningElement } from 'lwc';
export default class ChildComp extends LightningElement {
notifyParent() {
const event = new CustomEvent('childnotification', { bubbles: true });
this.dispatchEvent(event);
}
}
which sends a childnotification
event to parentComp
parentComp.html
<template>
<div onchildnotification={ghostMethod}>
<div onchildnotification={handleChildNotification}>
<lightning-textarea value="Parent Component"></lightning-textarea>
<c-child-comp></c-child-comp>
</div>
</div>
</template>
parentComp.js
import { LightningElement } from 'lwc';
export default class ParentComp extends LightningElement {
handleChildNotification() {
console.log('Child Event arrived');
}
}
As you can see, when the parent component receives childnotification
event, apart from invoking handleChildNotification
(which exists on
parentComp.js
) it's invoking ghostMethod
, which does not exist on parentComp.js
.
- Because of this reason, you will get this annoying
[NoErrorObjectAvailable] Script error
failure.
Points to take into account and why I consider this a Salesforce LWC Bug
parentComp.html
can be successfully deployed even if ghostMethod
does not exist on parentComp.js
- As of my experience, you only get this error if
ghostMethod
has never existed in the LWC. If it has existed in a previous LWC version it will not fail (even if the code is not there anymore)
Update
Another common reason why this error appears, is because an exception occurs on the handler method (in our case, handleChildNotification
). This is easier to identify and troubleshoot with the pause on exceptions
button of the browser development tools.