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

Type error in NodeJS 20, when lib: ["es2023"] #43

Closed
SooditK opened this issue Jan 22, 2024 · 4 comments · Fixed by #50
Closed

Type error in NodeJS 20, when lib: ["es2023"] #43

SooditK opened this issue Jan 22, 2024 · 4 comments · Fixed by #50
Labels
bug Something isn't working

Comments

@SooditK
Copy link

SooditK commented Jan 22, 2024

Describe the bug
I'm using NodeJS 20 and the following tsconfig.json for my expressjs application, Prisma Extension Kysely throws Type Error:
Type 'typeof import("PATH_TO_MY_PROJECT/node_modules/prisma-extension-kysely/dist/index")' has no call signatures.

To Reproduce
Steps to reproduce the behavior:

  1. You can create a basic express and prisma project (you can use npx try-prisma@latest and select rest-express)
  2. You install all the required dependencies (prisma-kysely, prisma-extension-kysely & kysely)
  3. Add the following code to schema.prisma file:
generator kysely {
  provider     = "prisma-kysely"
  output       = "../src/db"
  fileName     = "types.ts"
  enumFileName = "enums.ts"
}
  1. Run npx prisma generate
  2. Create a new file and can extend prisma there (like following):
import kyselyExtension from "prisma-extension-kysely";
import type { DB } from "./types.js";  // <--- the '.js' extension cuz Relative import paths need explicit file extensions in ECMAScript imports when --moduleResolution is node16
import { PrismaClient } from "@prisma/client";
import {
  Kysely,
  SqliteAdapter,
  SqliteIntrospector,
  SqliteQueryCompiler,
  Driver,
} from "kysely";

export const prisma = new PrismaClient().$extends(
  kyselyExtension({ // <--- ERROR: This expression is not callable.
    kysely: (driver: Driver) =>
      new Kysely<DB>({
        dialect: {
          createDriver: () => driver,
          createAdapter: () => new SqliteAdapter(),
          createIntrospector: (db) => new SqliteIntrospector(db),
          createQueryCompiler: () => new SqliteQueryCompiler(),
        },
        plugins: [],
      }),
  })
);

Expected behavior
No Type Errors 😄

Desktop (please complete the following information):

  • OS: macOS Sonoma 14.2.1 (23C71)

Additional context
tsconfig.json:

{
  "compilerOptions": {
    "lib": ["es2023"],
    "module": "node16",
    "target": "es2022",
    "strict": true,
    "esModuleInterop": true,
    "skipLibCheck": true,
    "forceConsistentCasingInFileNames": true,
    "moduleResolution": "node16",
    "sourceMap": true,
    "allowSyntheticDefaultImports": true,
    "noImplicitThis": true,
    "allowJs": true,
    "experimentalDecorators": true,
    "emitDecoratorMetadata": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "outDir": "dist/"
  },
  "exclude": ["node_modules"],
  "include": ["src/**/*"],
  "ts-node": {
    "esm": true,
    "experimentalSpecifierResolution": "node"
  }
}
@eoin-obrien
Copy link
Owner

Hi! Thanks for posting this issue - I've spun up a local project based on your example, but I can't seem to reproduce the type error. Could you link to a repo with a minimal reproduction, please? That should help me to get things investigated for you as soon as possible!

@SooditK
Copy link
Author

SooditK commented Jan 24, 2024

Hii! here's the link: https://github.com/SooditK/prisma-extension-kysely-typeissue
You can use any package manager (bun works as well)
Please do npm i and then add your Database Credentials in .env
after that, you can do npx prisma db push and you'll see the error in src/index.ts & src/db/prisma.ts
Optionally, you can do npx prisma db seed to seed the DB with dummy data

Thanks

@eoin-obrien
Copy link
Owner

Looks like an ESM vs CJS issue! I'll dig into it and let you know when I've got a solution posted. Thanks again!

@eoin-obrien eoin-obrien added the bug Something isn't working label Jan 24, 2024
@eoin-obrien
Copy link
Owner

This looks like it's been resolved by the new release! Using your sample repo:

npm install prisma-extension-kysely@latest
npm run build
npm run dev

It now works without any type errors! Thanks again for bringing this to my attention, much appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants