valtyr/prisma-kysely

Unknown error when run prisma generate

Closed this issue ยท 10 comments

i facing this error when run prisma generate

Error: 
Error: Debug Failure. Unhandled SyntaxKind: Unknown.

im using

"prisma": "^4.11.0",
"typescript": "^5.0.2"
janpio commented

Can you run with DEBUG=* set as an env var and share the full output you get?

DEBUG=* dotenv -e .env.dev -- prisma db push

  prisma:engines  binaries to download libquery-engine, migration-engine +0ms
  prisma:loadEnv  project root found at /Users/luccasrobert/Documents/GitHub/api/package.json +0ms
  prisma:tryLoadEnv  Environment variables not found at null +0ms
  prisma:tryLoadEnv  Environment variables not found at undefined +1ms
  prisma:tryLoadEnv  No Environment variables loaded +0ms
  prisma:getConfig  Using getConfig Wasm +0ms
  prisma:getConfig  config data retrieved without errors in getConfig Wasm +1ms
  prisma:loadEnv  project root found at /Users/luccasrobert/Documents/GitHub/api/package.json +5ms
  prisma:tryLoadEnv  Environment variables not found at null +3ms
  prisma:tryLoadEnv  Environment variables not found at undefined +0ms
  prisma:tryLoadEnv  No Environment variables loaded +1ms
Prisma schema loaded from prisma/schema.prisma
  prisma:getConfig  Using getConfig Wasm +3ms
  prisma:getConfig  config data retrieved without errors in getConfig Wasm +1ms
Datasource "db": MySQL database "my db name" at "planetscale url"
  prisma:getConfig  Using getConfig Wasm +3ms
  prisma:getConfig  config data retrieved without errors in getConfig Wasm +1ms
  prisma:migrateEngine:rpc  starting migration engine with binary: /Users/luccasrobert/Documents/GitHub/api/node_modules/@prisma/engines/migration-engine-darwin +0ms
  prisma:migrateEngine:rpc  SENDING RPC CALL {"id":1,"jsonrpc":"2.0","method":"schemaPush","params":{"force":false,"schema":"// This is your Prisma schema file,\n// learn more about it in the docs: https://pris.ly/d/prisma-schema\n\n// generator client {\n//   provider = \"prisma-client-js\"\n// }\n\n// generator kysely {\n//   provider = \"prisma-kysely\"\n//   output   = \"../src/db\"\n//   fileName = \"types.ts\"\n// }\n\ngenerator kysely {\n  provider = \"prisma-kysely\"\n\n  // Optionally provide a destination directory for the generated file\n  // and a filename of your choice\n  output   = \"../src/db\"\n  fileName = \"types.ts\"\n}\n\ndatasource db {\n  provider     = \"mysql\"\n  url          = env(\"DATABASE_URL\")\n  relationMode = \"prisma\"\n}\n\n// CREATE TABLE users (\n//   id INT AUTO_INCREMENT PRIMARY KEY,\n//   provider ENUM('facebook', 'google', 'apple', 'local') NOT NULL,\n//   provider_id VARCHAR(255) UNIQUE,\n//   email VARCHAR(255) UNIQUE NOT NULL,\n//   password VARCHAR(255),\n//   first_name VARCHAR(255),\n//   last_name VARCHAR(255),\n//   profile_picture_url VARCHAR(255),\n//   created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n//   updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP\n// );\n\n// CREATE TABLE user_providers (\n//   id INT AUTO_INCREMENT PRIMARY KEY,\n//   user_id INT NOT NULL,\n//   provider ENUM('facebook', 'google', 'apple', 'local') NOT NULL,\n//   provider_id VARCHAR(255) UNIQUE,\n//   created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,\n//   updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,\n//   FOREIGN KEY (user_id) REFERENCES users(id)\n// );\n\nmodel User {\n  id                  Int            @id @default(autoincrement())\n  public_id           String         @db.VarChar(30)\n  email               String         @unique\n  password            String?\n  firstName           String\n  lastName            String\n  profile_picture_url String?\n  userProviders       UserProvider[]\n  created_at          DateTime       @default(now())\n  updated_at          DateTime       @updatedAt\n\n  @@map(\"user\")\n}\n\nenum Provider {\n  GOOGLE\n  APPLE\n  LOCAL\n}\n\nmodel UserProvider {\n  id          Int      @id @default(autoincrement())\n  public_id   String   @db.VarChar(30)\n  User        User     @relation(fields: [user_id], references: [id])\n  user_id     Int\n  provider    Provider\n  provider_id String   @unique\n  created_at  DateTime @default(now())\n  updated_at  DateTime @updatedAt\n\n  @@index([user_id])\n  @@map(\"user_providers\")\n}\n\nmodel Pet {\n  id         Int      @id @default(autoincrement())\n  name       String\n  photo_url  String\n  species    String\n  breed      String\n  age        Int?\n  created_at DateTime @default(now())\n  updated_at DateTime @updatedAt\n\n  @@map(\"pet\")\n}\n"}} +6ms
  prisma:migrateEngine:stderr  {"timestamp":"2023-03-21T14:10:55.605625Z","level":"INFO","fields":{"message":"Starting migration engine RPC server","git_hash":"8fde8fef4033376662cad983758335009d522acb"},"target":"migration_engine"} +0ms

The database is already in sync with the Prisma schema.

Running generate... (Use --skip-generate to skip the generators)
  prisma:getConfig  Using getConfig Wasm +5s
  prisma:getConfig  config data retrieved without errors in getConfig Wasm +1ms
  prisma:getDMMF  Using getDmmf Wasm +0ms
  prisma:getDMMF  Using given datamodel +1ms
  prisma:getDMMF  dmmf data retrieved without errors in getDmmf Wasm +7ms
Error: Debug Failure. Unhandled SyntaxKind: Unknown.
    at pipelineEmitWithHintWorker (/Users/luccasrobert/Documents/GitHub/api/node_modules/typescript/lib/typescript.js:110767:13)
    at pipelineEmitWithHint (/Users/luccasrobert/Documents/GitHub/api/node_modules/typescript/lib/typescript.js:110308:9)
    at pipelineEmitWithComments (/Users/luccasrobert/Documents/GitHub/api/node_modules/typescript/lib/typescript.js:114087:7)
    at pipelineEmit (/Users/luccasrobert/Documents/GitHub/api/node_modules/typescript/lib/typescript.js:110257:7)
    at emit (/Users/luccasrobert/Documents/GitHub/api/node_modules/typescript/lib/typescript.js:110225:7)
    at emitTypeAliasDeclaration (/Users/luccasrobert/Documents/GitHub/api/node_modules/typescript/lib/typescript.js:112190:7)
    at pipelineEmitWithHintWorker (/Users/luccasrobert/Documents/GitHub/api/node_modules/typescript/lib/typescript.js:110494:20)
    at pipelineEmitWithHint (/Users/luccasrobert/Documents/GitHub/api/node_modules/typescript/lib/typescript.js:110308:9)
    at pipelineEmitWithComments (/Users/luccasrobert/Documents/GitHub/api/node_modules/typescript/lib/typescript.js:114087:7)
    at pipelineEmit (/Users/luccasrobert/Documents/GitHub/api/node_modules/typescript/lib/typescript.js:110257:7)

  prisma:getConfig  Using getConfig Wasm +691ms
  prisma:getConfig  config data retrieved without errors in getConfig Wasm +1ms

Running with

OS: macOS Ventura
Packages:
"prisma": "^4.11.0"
"typescript": "^5.0.2"
"prisma-kysely": "^1.0.7"
valtyr commented

Would you also be willing to share your schema so that I can attempt to reproduce this issue?

I did some tests and the problem seems to be with TS, using typescript@4.9.5 works fine but with typescript@5.0.2 cant work

my schema

model User {
  id                  Int            @id @default(autoincrement())
  public_id           String         @db.VarChar(30)
  email               String         @unique
  password            String?
  first_name           String
  last_name            String
  profile_picture_url String?
  userProviders       UserProvider[]
  created_at          DateTime       @default(now())
  updated_at          DateTime       @updatedAt

  @@map("user")
}

enum Provider {
  GOOGLE
  APPLE
  LOCAL
}

model UserProvider {
  id          Int      @id @default(autoincrement())
  public_id   String   @db.VarChar(30)
  User        User     @relation(fields: [user_id], references: [id])
  user_id     Int
  provider    Provider
  provider_id String   @unique
  created_at  DateTime @default(now())
  updated_at  DateTime @updatedAt

  @@index([user_id])
  @@map("user_providers")
}
janpio commented

Does the same problem also happen when you test with the newer typescript and just the default Prisma Client generator, without prisma-kysely? If so, this might actually be an issue for the prisma/prisma repo and our first reported problem with Typescript 5.x ๐Ÿ˜†

valtyr commented

I think I might have found the issue. This library executes factory code from the typescript@4.6.2 package directly for code generation, but I've only listed Typescript as a devDependency in the package.json file. That means the version of Typescript listed in your package.json is likely taking over and crashing because of breaking API changes.

I'm going to try creating a PR and releasing a snapshot with updated dependencies.

brb

valtyr commented

@luccasr73 Could you try using snapshot version prisma-kysely@0.0.0-snapshot-20230321203645 and check if the problem persists?

@janpio no problems with prisma-client-js and typescript@5.0.2
@valtyr prisma-kysely@0.0.0-snapshot-20230321203645 works fine with typescript@5.0.2
thanks for fixing it so fast

valtyr commented

@luccasr73 Awesome! I'll merge it in and create a release then. Thanks for reporting this issue ๐Ÿ˜„
@janpio It seems like prisma/prisma is safe... for now ๐Ÿฆธ