-
-
Notifications
You must be signed in to change notification settings - Fork 164
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
Error TS2351 "This expression is not constructable" for new SchemaBuilder #597
Comments
Thanks for the report and reproduction! I spent some time looking at this today, and I am very unclear on how this is supposed to work for packages supporting both esm and cjs. Adding It also looks like if I duplicate type declaration into the esm directory and remove "types" "exports.types" from package.json things would also work. This is a potential path forward, but would require 3 copies of the type definitions to be shipped. I kinda suspect this might be a bug in typescript where they are not properly account for the combination of "nodeNext" with packages that define "exports" for both cjs and esm. I won't have much time until late next week to dig into this more. If you have ideas on a path forward I am happy to help implement, but I don't really have a good enough understanding of how all the different config options interact to know how to proceed at the moment. |
After playing around with the error repoduction repo I succeed to make it works by changing this files : src/index.mtsimport { default as SchemaBuilder } from '@pothos/core'; // was import SchemaBuilder from "@pothos/core";
const builderOptions = {
plugins: [],
};
export const builder = new SchemaBuilder<{}>(builderOptions); tsconfig.json{
"compilerOptions": {
"sourceMap": true,
"outDir": "dist",
"rootDir": "src",
"target": "es2021",
"module": "node16",
"strict": true,
"lib": ["es2021"],
"esModuleInterop": true,
"skipLibCheck": true
},
"exclude": ["dist"]
} BUT it only works up to Typescript version
|
Run into the same issue as well. Thanks for sharing. |
relevant typescript issue: microsoft/TypeScript#50762 Did some debugging, and it looks like the issue is that in nodeNext mode pothos at its root is a "cjs" package, and the "dts" files inside are treated as cjs in compatability mode. This makes ts think that the default export is an object with a "default" property, rather than being the builder class itself. |
Just published a new version of all Pothos packages that I'm hoping will fix this. Let me know if that works for you |
Issue fixed for me but still uncompatible with typescript above version 4.8.2 |
pushed another update earlier today. Ended up duplicating the all the .d.ts files into the esm directory. Not an optimal solution, but it should work across all versions (and hopefully all ts options) now |
Hum, now it's not working anymore :/ TSError: ⨯ Unable to compile TypeScript: 1 import SchemaBuilder from '@pothos/core' |
looks like the build job is copying files differently in CI than on my machine. Must be a linux vs osx difference in how |
|
okay, new version actually has the definition files in the expected locations |
Still not working :/ |
something still seems broken though . |
Good old |
the esm/package.json that marks the esm directory as being |
okay, I think it's fixed for real this time. d.ts files are in the right place, the pasckage.json file for the esm directory is restored, the repro from above now works on both 4.8.2 and 4.8.4 (for me at least). Let me know if you are still running into issues after this |
Sorry but, now when implementing SchemaBuilder, the instance is marked as any :/ |
I've tried a bunch of different combinations of options using the repro repo from above and can't reproduce that, any more info on how to reproduce the |
Here is a little sample of my own project |
thanks, I think I see what's going in. Looks like some imports int the esm definintions are not working correctly because they are importing directories rather than explicitly asking for |
Sorry this has had so many broken versions. I am hoping it's actually right this time. Needed to transform all the imports to include the full file path. Mind testing one more time? |
No problemo ;) I love this lib so I'm glad to help. |
We had to update our tsconfig file and this resulted in a new typescript error when creating a new SchemaBuilder.
Code:
Error:
Changes in our tsconfig:
"module": "commonjs"
to"module": "NodeNext"
"moduleResolution": "NodeNext"
Full tsconfig.json:
Package versions:
Repository with error reproduction:
Repository: builder-ts-error-reproduction
The text was updated successfully, but these errors were encountered: