micro-sentry icon indicating copy to clipboard operation
micro-sentry copied to clipboard

[BUG] ReferenceError: XMLHttpRequest is not defined on SSR

Open renatoaraujoc opened this issue 1 year ago • 1 comments

🐞 Bug report

Description

Dispatching an error on server-side of Angular will error with XMLHttpRequest not defined.

Reproduction

No need to reproduce this, afaik XMLHttpRequest is not a defined in node environments.

Expected behavior

The library has to provide some sort of http-request api (to at least inform in the readme that we're supposed to provide it on the global window object) to report errors on server-side if its supposed to. Or completely ignore server-side errors and let the browser handle those as they implement the XMLHttpRequest object.

Versions

If needed:

  • Chrome
  • Angular 15.2.2

Additional context

This is my server window object (necessary for lots of stuff to work): Screenshot 2023-04-10 at 11 40 29 This is the error: Screenshot 2023-04-10 at 11 36 41

renatoaraujoc avatar Apr 10 '23 14:04 renatoaraujoc

Hello,

Fixed it with:

import XMLHttpRequest from 'xhr2';
(global as any).XMLHttpRequest = XMLHttpRequest;

in server.ts.

I'm leaving this opened so you guys can maybe provide 'xhr2' as dependency, detect if XMLHttpRequest is present, if not, use this library.

It's up to you :)

renatoaraujoc avatar Apr 10 '23 21:04 renatoaraujoc