martinsileno / pubg-typescript-api

TypeScript wrapper on official PUBG API.
MIT License
12 stars 9 forks source link

await on api call throwing error #11

Closed jimwilde closed 6 years ago

jimwilde commented 6 years ago

I have the following function:

getPlayers: async (gamerTags: string[]) => await Player.filterByName(pubgApi, gamerTags);

Whenever I call it I get the following error: "ReferenceError: regeneratorRuntime is not defined".

It seems the api wrapper isn't able to handle the async/await. Is there something I should know?

Thanks.

jimwilde commented 6 years ago

Edit: Nevermind. Discovered the problem was that the compiled version of the API wrapper has already had babel convert async/await to generators.

In order for my project to allow async/await against the api wrapper, I had to npm i @babel/polyfill, and import it at the top of my service that wraps the api wrapper.

Eg, ` import '@babel/polyfill'; import { Match, PlatformRegion, Player, PubgAPI } from 'pubg-typescript-api';

const API_KEY = api_key;

const pubgApi = new PubgAPI(API_KEY, PlatformRegion.XBOX_EU);

export const api = { getMatch: async (playerId: string, matchId: string) => { const matchData = await Match.get(pubgApi, matchId); return { matchData, participant: matchData.getParticipantById(playerId) }; }, getPlayers: async (gamerTags: string[]) => await Player.filterByName(pubgApi, gamerTags) }; `