ghoshRitesh12 / aniwatch

📦 A scraper package serving anime information from hianime.to
https://www.npmjs.com/package/aniwatch
MIT License
15 stars 9 forks source link

Typescript support #2

Open wasmake opened 1 month ago

wasmake commented 1 month ago

Describe the bug

The lib is giving errors on typescript when default config is used

Expected behavior

Using same code as the example:

`import { HiAnime, HiAnimeError } from "aniwatch";

const hianime = new HiAnime.Scraper();

try { const result: HiAnime.ScrapedAnimeAboutInfo = await hianime.getInfo( "steinsgate-3" ); console.log(result); } catch (err) { console.error(err instanceof HiAnimeError, err); }`

In a Typescript + NestJs environment with the next tsbuild.config

{ "compilerOptions": { "module": "CommonJS", "moduleResolution": "node", "declaration": true, "removeComments": true, "emitDecoratorMetadata": true, "experimentalDecorators": true, "target": "es2020", "sourceMap": true, "outDir": "./dist", "baseUrl": "./", "incremental": true, "skipLibCheck": true, "strictNullChecks": false, "noImplicitAny": false, "strictBindCallApply": false, "forceConsistentCasingInFileNames": false, "noFallthroughCasesInSwitch": false, "esModuleInterop": true, "allowSyntheticDefaultImports": true }, "include": [ "./src/**/*" ], "exclude": [ "node_modules" ] }

Actual behavior

Gives the error:

const aniwatch_1 = require("aniwatch");

Error [ERR_REQUIRE_ESM]: require() of ES Module

Instead change the require of index.js in [...] to a dynamic import() which is available in all CommonJS modules.

Additional context

Typescript + NestJs

Apparently lib only includes the compiled "dist" javascript, so when tryong to run it in an "Typescript environment" such as the development server, gives the error.

ghoshRitesh12 commented 3 weeks ago

This library doesn't support CJS and it's intentional. This maybe the reason why those errors are occurring.