-
Notifications
You must be signed in to change notification settings - Fork 19
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
Typescript error: this expression is not constructable #63
Comments
I tried a few things to fix this from my own code like import { default as Anilist } from 'anilist-node'; But it didn't work. I had to edit the module itself to make it work. I'll offer a PR. |
I actually wanted to suggest a PR but I'm not sure if what I did was the right way to do it as it introduces a breaking change. Basically, For some reason, with |
Can you provide more information about this with your TSConfig and/or snippet of code with the AniList import? I have been unsuccessful trying to replicate the issue. Using the moduleResolution key, I've gotten import Anilist from "anilist-node";
const anilist = new Anilist();
anilist.genres().then(data => { console.log(data); }); For additional reference, this is my TSConfig file that I used for it. I tried both es2017 and es2022 with no luck.
|
Thanks for the quick reply! Here's the tsconfig.json for my project : {
"compilerOptions": {
"target": "ESNext",
"module": "es2022",
// Search under node_modules for non-relative imports.
"moduleResolution": "node16",
// Process & infer types from .js files.
"allowJs": false,
// Don't emit; allow esbuild to transform files.
"noEmit": true,
// Enable strictest settings like strictNullChecks & noImplicitAny.
// true is better but requires a global refactoring.
"strict": false,
// Disallow features that require cross-file information for emit.
"isolatedModules": false,
// Import non-ES modules as default imports.
"esModuleInterop": true,
// Import constants from JSON (locales).
"resolveJsonModule": true,
"sourceMap": true,
"inlineSources": true,
"sourceRoot": "/",
"outDir": "dist/",
"pretty": true,
"removeComments": true,
"downlevelIteration": true,
"noUnusedParameters": true,
"noUnusedLocals": true
},
"include": [
"src"
]
} |
Note : I also have |
Yep, this is the issue. Added that one line in my package.json with my TSConfig and got the error. From what I found, it's the combination of |
The problem is that I actually did specify |
Yes, I see it. I think I got a full grasp of what's needed now.
Looping back to this, I think this is the fix that we need to solve it. Since you need If you want to make a PR for this, go for it. I don't view this as a breaking change since:
Just following the Contributing guide and it'll be fixed in no time. |
Closing as #64 fixes this issue. |
Hello again. Sadly, it actually doesn't work :) While typescript isn't whining anymore, I should have built and tested it all, because as soon as the code is executed, node complains I'm sorry about that. I tried to twist how I called/imported anilist-node but it just would either make typescript complain or node complain on runtime. In the end I gave up and added a I looked into this with a knowledgeable friend and he thinks that it's an authentic typescript bug that might get fixed later because there's no valid reason why it should believe that Anilist() is not constructable as there's a constructor method, it's a class and all... Sorry about the PR again ^^ It might be interesting to reopen this until it gets fixed in Typescript as ESM is a rather new feature of typescript itself. |
That is pretty weird. I didn't get that error when I compiled and ran it so I don't know what is happening. I'll reopen this in the meantime. 👍 |
Description
When using
moduleResolution: node16
ornodenext
in tsconfig.json, building with a call to the module causes the following error :Steps to Reproduce
moduleResolution: node16
Anilist
in your code as described in the README.Environment
Node.js Version: 18.12.1 (tyepscript version 5.0.2)
AniList-Node Version: 1.13.1
Thanks for looking into this! This would help a lot with a project I'm trying to keep up-to-date.
The text was updated successfully, but these errors were encountered: