node-twitch icon indicating copy to clipboard operation
node-twitch copied to clipboard

TypeError: TwitchApi is not a constructor

Open SteeledSlagle13 opened this issue 2 years ago • 1 comments

running with a typescript application

"typescript": "^4.6.2"

import TwitchApi from 'node-twitch';
const twitch = new TwitchApi({
      client_id: environment.TWITCH_AUTH.client_id,
      client_secret: environment.TWITCH_AUTH.client_secret,
});
const user = await twitch.getUsers([name]);

I get this error when the method gets called

file:///F:/bot/src/commands/utility/twitch.command.ts:25 const twitch = new TwitchApi({ ^ TypeError: TwitchApi is not a constructor

SteeledSlagle13 avatar Apr 07 '22 21:04 SteeledSlagle13

Your import seems not correct, Have you tried to import it like that :

const TwitchApi = require('node-twitch').default;

I tried to reproduce it and the .default fixed it. Hope it helps. I wish you an excellent day

adan-ea avatar May 04 '22 11:05 adan-ea