question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

prisma generates invalid typescript syntax

See original GitHub issue

Bug 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

  1. Run prisma init in a fresh directory
  2. Copy the schema.prisma (see below)
  3. Run prisma generate
  4. Take a look at node_models/.prisma/client/index.d.ts and search for types starting with Game_server_port.

You will notice 2 issues:

  1. The types contain dots which is invalid TypeScript syntax.
  2. The types are defined with an uppercase starting letter, but when referenced (in GameServerPortWhereUniqueInput), they are used with a lowercase starting letter. This results in Cannot 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:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
pantharshit00commented, Oct 30, 2020

@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.

1reaction
P4sca1commented, Oct 20, 2020

prisma migrate generated them.

From https://www.prisma.io/docs/reference/tools-and-interfaces/prisma-schema/prisma-schema-reference/#arguments-5:

The name of the index in the underlying database (Prisma generates an index name that respects identifier length limits if you do not specify a name. Prisma uses the following naming convention: tablename.field1_field2_field3_unique)

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found