Using react-papaparse in the Next.js getStaticProps - XMLHttpRequest is not defined

691 Views Asked by At

I am trying to use papaparse inside my Next.js page. I am using react-papaparse package which is a React wrapper for Papaparse. I am trying to parse remote CSV file inside getStaticProps() function but the error I get is XMLHttpRequest is not defined.

I know that getStaticProps() is executed on Node.js but I don't know how to use react-paparse correctly to avoid XMLHttpRequest call. Here is my code:

// index.js Next.js page

import { usePapaParse } from "react-papaparse";

export async function getStaticProps(context) {
  const { readRemoteFile } = usePapaParse();
  readRemoteFile(googleSheetUrl, {
    complete: (results) => {
      console.log("PAPAPARSE::complete", results)
    },
  });
}
0

There are 0 best solutions below