Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: kitsu_1.default is not a constructor #1047

Open
benchaikin opened this issue Dec 17, 2024 · 1 comment
Open

TypeError: kitsu_1.default is not a constructor #1047

benchaikin opened this issue Dec 17, 2024 · 1 comment
Assignees

Comments

@benchaikin
Copy link

I'm attempting to use Kitsu 10.1.5 with Nest.js on node 22.6.0 with TypeScript 5.7.2.

import Kitsu from 'kitsu';

export class SomeService {
  private readonly api: Kitsu;
  
  constructor {
    this.api = new Kitsu({ baseURL: 'https://some.api.com/v1', pluralize: false });
  }
}

and getting the following error:

TypeError: kitsu_1.default is not a constructor

After some fiddling I was able to get it work with arguably one of the worst hacks of modern history:

import * as Kitsu from 'kitsu';

export class SomeService {
  private readonly api: Kitsu.default;
  
  constructor {
    const hack = Kitsu.default;
    const str = `new Kitsu({baseURL: 'https://some.api.com/v1', pluralize: false})`;
    this.api = eval(str);
  }
}
@wopian
Copy link
Owner

wopian commented Dec 17, 2024

It looks like it is trying to load the commonJS Kitsu package instead of the ESM Kitsu package.

Legacy CommonJS exports cannot be imported correctly by ESM without using that * syntax as a workaround (not the eval part)

However, you should be able to force it to use the .mjs version if your compiler is refusing to use the correct version of the package (you're using ESM syntax, so it should be loading ESM)

The package is a native ES module package, so I've never encountered this wonky behaviour.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants