AstroJS & Prismic giving "XMLHttpRequest is not defined" error?

Hi guys,

I'm trying to use Prismic with AstroJS, following the Javascript documentation and also the following video ->Building with Astro & Prismic - w/ Nate Moore - YouTube, but I'm hitting this error when I try to pull data from the api.
"[executing astro] ReferenceError: XMLHttpRequest is not defined"
Not sure how to resolve this and why this didn't show up for the demo video too. =(
Anyone has any idea?

Hello @kelvin.zhao

Welcome to the Prismic community, and thanks for reaching out to us.

XMLHttpRequest is a built-in object in web browsers . Try to install it separately: (xmlhttprequest - npm),

  1. Install it with npm,
npm install xmlhttprequest
  1. Now, you can require it in your code.
var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;
var xhr = new XMLHttpRequest();

Let me know if it still doesn't solve your issue. I'll be happy to debug it more.

Thanks,
Priyanka