raygun4js icon indicating copy to clipboard operation
raygun4js copied to clipboard

ReferenceError: window is not defined. This library does not work with SSR/SSG/Node env

Open TSMMark opened this issue 5 years ago • 2 comments

It would be great if this library did not require window to exist. Otherwise this can't be used with a next.js app or be imported during SSG.

What would it take to check typeof window !== 'undefined' or something before referencing the window object? Or at least not reference window when the library is imported, and instead wait until some raygun function is invoked (lazy)?

Or is there another solution?

Thanks


Related: #301

TSMMark avatar Feb 04 '21 15:02 TSMMark

Hi @TSMMark.

We're aware of the difficulties of using raygun4js with frameworks like Next.js and Remix, and we're considering how best to improve the UX for integrating Raygun with these frameworks.

In the meantime, we have documentation for integrating raygun4js for reporting clientside errors with Next.js.

We also have documentation for using raygun4node to report server-side errors using Next.js and Remix.

In future we may support both Node and the browser in a single library, but presently this is the best way to go, and also lets you utilise the full feature-set of each library.

Widdershin avatar May 18 '22 05:05 Widdershin

Hi @TSMMark

If you have a look here https://raygun.com/documentation/language-guides/javascript/angular-two/#using-raygun-with-server-side-rendering

It shows how to use SSR/SSG in Angular. That may be another way of getting this to work for you.

darcythomas avatar May 18 '22 21:05 darcythomas