Skip to content

Polyfill XMLHttpRequest on the server #17404

Answered by jamesmosier
ryyppy asked this question in Help
Discussion options

You must be logged in to vote

I think you'd want to include this global.XMLHttpRequest = xhr.XMLHttpRequest; inside your getStaticProps function call.

import xhr from 'xmlhttprequest';

export async function getStaticProps(ctx) {
  global.XMLHttpRequest = xhr.XMLHttpRequest;  
}

Also if you are able to I'd recommend switching all xhr requests to use fetch. Next polyfills this on the server by default https://nextjs.org/docs/basic-features/supported-browsers-features#server-side-polyfills

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ryyppy
Comment options

Answer selected by ryyppy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants