I have a LWC that is used in different orgs. In one of them, when I dispatch an event like:
this.dispatchEvent( new CustomEvent( 'press' ));
I am getting the [NoErrorObjectAvailable] Script error
in that line (as per the Stack trace).
If I comment that line, then the error disappears.
This is the most similar question I have found but I am making no use of event.target
so unfortunately it does not help.
What can I be doing wrong?
Best Answer
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}
, whereghostMethod
does not exist in the JS controller.Long version
Let's say we have a child component like the following:
childComp.html
childComp.js
which sends a
childnotification
event toparentComp
parentComp.html
parentComp.js
As you can see, when the parent component receives
childnotification
event, apart from invokinghandleChildNotification
(which exists onparentComp.js
) it's invokingghostMethod
, which does not exist onparentComp.js
.[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 ifghostMethod
does not exist onparentComp.js
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 thepause on exceptions
button of the browser development tools.