subhero24 / vttl-api

A javascript library to use the VTTL table tennis API in the browser
3 stars 1 forks source link

Readme default code ReferenceError: XMLHttpRequest #13

Open Jan-DaCuMa opened 1 month ago

Jan-DaCuMa commented 1 month ago

I have this in my page.tsx as you mentioned in the readme. I also did an npm i and npm i vttl-api. This is the code I have

// pages/index.js
"use client";
import { provinces, getClubs } from 'vttl-api';

export default async function Home() {

for (let province of provinces) {
    let clubs = await getClubs({ ClubCategory: province.id });

}
  return <div>Haai</div>
}

When I go to this page, I see in the logs: ⨯ ReferenceError: XMLHttpRequest is not defined at new Promise (<anonymous>) at Home (./app/page.tsx:13:77) digest: "4248625284" GET / 500 in 632ms

Without the code of vttl-api, it works.

Can you take a look at it? Kr.

Jan-DaCuMa commented 1 month ago

Fyi, I use node v20

subhero24 commented 1 month ago

Running the package server side will not work as the official API is a SOAP XML api. The browser has a native XML parser, but node does not. So make sure getClubs runs on the client.