Can’t add event listener to window error event in module

I have been trying to add an error handler to the window object in my module class and no matter what I’ve tried it doesn’t work. The same code works when it is on the HTML page but not in a module. This is from a module:

class MyModule {
   showErrorsInDialog() {
      var output = "";
      window.addEventListener('error', this.errorHandler);
      
      window.onerror = (message, url, lineNumber, columnNumber, error) => {
         !isNaN(lineNumber) ? output += "Line " + lineNumber + " " : null;
         !isNaN(columnNumber) ? output += "Column " + columnNumber + " " : null;
         output += message;
         url!=null ? output += " at " + url + " " : null;
         output += "n";
         console.log(output);
      }
   }

   errorHandler(event) {
      console.log("error event" + event)
   }
}

My page is slightly different but this might be the HTML. I haven’t used inline modules:

<script type="module">
var myModule = new MyModule();
</script>

Is there a reason I can’t add an event handler on the error object? Other events seem to work fine.