zSoulweaver / kient

TypeScript-First Client Library for Kick.com
https://kient.pages.dev/
MIT License
29 stars 11 forks source link

SyntaxError: await is only valid in async functions and the top level bodies of modules #21

Closed jedai47 closed 3 months ago

jedai47 commented 3 months ago

Hi i only tried the example on : https://kient.pages.dev/guide/getting-started and got the following error:

`ts-node api.ts /home/walid/kick/api.ts:4 const kient = await kient_1.Kient.create(); ^^^^^

SyntaxError: await is only valid in async functions and the top level bodies of modules at internalCompileFunction (node:internal/vm:73:18) at wrapSafe (node:internal/modules/cjs/loader:1274:20) at Module._compile (node:internal/modules/cjs/loader:1320:27) at Module.m._compile (/usr/local/lib/node_modules/ts-node/src/index.ts:1618:23) at Module._extensions..js (node:internal/modules/cjs/loader:1414:10) at Object.require.extensions. [as .ts] (/usr/local/lib/node_modules/ts-node/src/index.ts:1621:12) at Module.load (node:internal/modules/cjs/loader:1197:32) at Function.Module._load (node:internal/modules/cjs/loader:1013:12) at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:128:12) at phase4 (/usr/local/lib/node_modules/ts-node/src/bin.ts:649:14)`

zSoulweaver commented 3 months ago

Sounds like your environment doesn't support top level await. Either put the create method into an async function and call that, or use an async IIFE.