prisma generates invalid typescript syntax
See original GitHub issueBug description
When using dots in index names, the generated prisma-client-js
exports types that includes these dots, which is invalid TypeScript syntax.
This bug results in the project using prisma not being able to compile with tsc
, which is a major problem.
How to reproduce
- Run
prisma init
in a fresh directory - Copy the
schema.prisma
(see below) - Run
prisma generate
- Take a look at
node_models/.prisma/client/index.d.ts
and search for types starting withGame_server_port.
You will notice 2 issues:
- The types contain dots which is invalid TypeScript syntax.
- The types are defined with an uppercase starting letter, but when referenced (in
GameServerPortWhereUniqueInput
), they are used with a lowercase starting letter. This results inCannot find name
errors.
Expected behavior
Since index names with dots inside them are the prisma default, these should be supported, e.g. by replacing dots with underscores maybe. Also the types should be correctly referenced.
Prisma information
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "mysql"
url = env("DATABASE_URL")
}
model GameServer {
id Int @id @default(autoincrement())
ports GameServerPort[]
@@map("game_server")
}
model GameServerPort {
id Int @id @default(autoincrement())
/// varchar(32)
identifier String
protocol GameServerPortProtocol
/// unsigned smallint, container port
number Int
/// unsigned smallint, host port
binding Int
gameServerId Int
/// ON UPDATE CASCADE, ON DELETE CASCADE
gameServer GameServer @relation(fields: [gameServerId], references: [id])
@@unique([gameServerId, binding, protocol], name: "game_server_port.gameServerId_binding_protocol_unique")
@@unique([gameServerId, identifier], name: "game_server_port.gameServerId_identifier_unique")
@@unique([gameServerId, number, protocol], name: "game_server_port.gameServerId_number_protocol_unique")
@@map("game_server_port")
}
enum GameServerPortProtocol {
TCP
UDP
@@map("game_server_port_protocol")
}
Environment & setup
- OS: macOS
- Database: MySQL
- Node.js version: 12.16.2
- Prisma version:
@prisma/cli : 2.9.0
@prisma/client : 2.9.0
Current platform : darwin
Query Engine : query-engine 369b3694b7edb869fad14827a33ad3f3f49bbc20 (at ../../.npm/_npx/18009/lib/node_modules/@prisma/cli/query-engine-darwin)
Migration Engine : migration-engine-cli 369b3694b7edb869fad14827a33ad3f3f49bbc20 (at ../../.npm/_npx/18009/lib/node_modules/@prisma/cli/migration-engine-darwin)
Introspection Engine : introspection-core 369b3694b7edb869fad14827a33ad3f3f49bbc20 (at ../../.npm/_npx/18009/lib/node_modules/@prisma/cli/introspection-engine-darwin)
Format Binary : prisma-fmt 369b3694b7edb869fad14827a33ad3f3f49bbc20 (at ../../.npm/_npx/18009/lib/node_modules/@prisma/cli/prisma-fmt-darwin)
Studio : 0.296.0
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:10 (4 by maintainers)
Top Results From Across the Web
Invalid typescript syntax generated #5740 - prisma ... - GitHub
When generating prisma client types, a wrong syntax is generated in the module type definition. The error steps from trying to use template ......
Read more >Invalid create() invocation with prisma - Stack Overflow
The solution was to change the name of the model from sdk_error -> sdkError. Seems like the underscore breaks the name of the...
Read more >Advanced type safety (Reference) - Prisma
Prisma Client provides full type safety for queries, even for partial queries or included relations. This page explains how to leverage the generated...
Read more >Operating against partial structures of your model types - Prisma
This page documents various scenarios for using the generated types from the Prisma namespace.
Read more >Error message reference - Prisma
Prisma Client throws a PrismaClientInitializationError exception if something goes wrong when the query engine is started and the connection to the database is ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@P4sca1 Multi field indexes are added to
WhereUnique
inputs as you get a unique row by using a unique combination of values of the index fields.prisma migrate
generated them.From https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/prisma-schema-reference/#arguments-5: