pothos: Error TS2351 "This expression is not constructable" for new SchemaBuilder

We had to update our tsconfig file and this resulted in a new typescript error when creating a new SchemaBuilder.

Code:

export const builder = new SchemaBuilder<{}>(builderOptions);

Error:

error TS2351: This expression is not constructable.
Type 'typeof import("C:/Users/[...]/node_modules/@pothos/core/dts/index")' has no construct signatures.

Changes in our tsconfig:

  • Changed "module": "commonjs" to "module": "NodeNext"
  • Added line "moduleResolution": "NodeNext"

Full tsconfig.json:

{
  "compilerOptions": {
    "target": "ESNext",
    "module": "NodeNext",

    "allowJs": true,
    "declaration": false,
    "outDir": "built",
    "maxNodeModuleJsDepth": 10,
    "strict": true,

    "moduleResolution": "NodeNext",

    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "skipLibCheck": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}

Package versions:

"@pothos/core": "^3.20.0"
"typescript": "^4.8.2"

Repository with error reproduction: Repository: builder-ts-error-reproduction

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 6
  • Comments: 22 (13 by maintainers)

Most upvoted comments

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?

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

the esm/package.json that marks the esm directory as being "type": "module" got deleted for pothos/core… pushing a fix

looks like the build job is copying files differently in CI than on my machine. Must be a linux vs osx difference in how cp works. I think this should be easy to fix, one minute

Just published a new version of all Pothos packages that I’m hoping will fix this. Let me know if that works for you

After playing around with the error repoduction repo I succeed to make it works by changing this files :

src/index.mts

import { 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 4.8.2 ! If you install version 4.8.3 you will get

src/index.mts:7:28 - error TS2351: This expression is not constructable.
  Type 'typeof import("C:/Users/mboidin/Documents/Playgrounds/builder-ts-error-reproduction/node_modules/@pothos/core/dts/index")' has no construct signatures.

7 export const builder = new SchemaBuilder<{}>(builderOptions);