zod-prisma-types icon indicating copy to clipboard operation
zod-prisma-types copied to clipboard

Error updating prisma and zod-prisma-types

Open gascenciom1998 opened this issue 1 year ago • 10 comments

Recently updated @prisma/client and prisma from versions 4.10.1 to 4.15.0. I also updated zod-prisma-types from 2.5.4 to 2.7.3. I have also ensured that we are using zod version 3.21.1 (since I know there is a known issue with higher versions)

Since then, generating zod types seems to work but when trying to build my application I get the following error:

prisma/generated/zod/index.ts(6347,14): error TS2451: Cannot redeclare block-scoped variable 'ProductListRelationFilterSchema'.
prisma/generated/zod/index.ts(6610,14): error TS2322: Type 'ZodObject<{ every: ZodOptional<ZodLazy<ZodType<ProductWhereInput, ZodTypeDef, ProductWhereInput>>>; some: ZodOptional<...>; none: ZodOptional<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>' is not assignable to type 'ZodType<ProductListRelationFilter, ZodTypeDef, ProductListRelationFilter>'.
Types of property '_type' are incompatible.
     Type '{ every?: ProductWhereInput | undefined; some?: ProductWhereInput | undefined; none?: ProductWhereInput | undefined; }' has no properties in common with type 'ProductListRelationFilter'.
 prisma/generated/zod/index.ts(6610,14): error TS2451: Cannot redeclare block-scoped variable 'ProductListRelationFilterSchema'.

gascenciom1998 avatar Jun 14 '23 21:06 gascenciom1998

Could someone gives us the latest tested package versions for @prisma/client, prisma, zod-prisma-types and zod?

odysseaspapadimas avatar Jun 15 '23 11:06 odysseaspapadimas

@gascenciom1998 @odysseaspapadimas I'll look into it. the generator currently uses @prisma/internals": "^4.13.0 and @prisma/generator-helper": "^4.13.0. I'll update to the latest versions and see if I can reproduce the error

chrishoermann avatar Jun 15 '23 11:06 chrishoermann

in the latest version I updated the relevant prisma packages to 4.15, tested it with my schema and was able to compile it. Can you please test your setup with the latest version and see if the bug disappears? If not, can you please provide me with a prisma schema where the bug occures?

chrishoermann avatar Jun 15 '23 18:06 chrishoermann

@chrishoermann This schema.prisma results in the error from my original post, using latest versions of zod-prisma-types, prisma, and @prisma/client:

generator jsclient {
  provider        = "prisma-client-js"
  previewFeatures = ["fullTextSearch"]
  binaryTargets   = ["native", "rhel-openssl-1.0.x"]
}

generator zod {
  provider = "zod-prisma-types"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model ProductList {
  id       String           @id @default(uuid())
  products RefProductList[]
}

model RefProductList {
  productId String
  listId    String
  list      ProductList @relation(fields: [listId], references: [id])
  product   Product     @relation(fields: [productId], references: [id])

  @@id([productId, listId])
}

model Product {
  // PK and FK
  id         String @id @default(uuid())
  categoryId String

  // relations
  category Category         @relation(fields: [categoryId], references: [id])
  lists    RefProductList[]
}

model Category {
  id       String    @id @default(uuid())
  products Product[]
}

gascenciom1998 avatar Jun 15 '23 20:06 gascenciom1998

Bumping - we're having the same issue when upgrading Prisma from 4.10.x to any higher version.

samthompsonkennedy avatar Jun 22 '23 02:06 samthompsonkennedy

Any update on this? I am also getting a error on next build. The generate is fine but there is a type error of string is not assigned to undefined and not sure why it is saying this.

artem-alek avatar Jul 14 '23 23:07 artem-alek

Bumping again, still no luck with upgrading. Stuck on Prisma 4.10.x which is now causing us other problems.

Any update on this? I am also getting a error on next build. The generate is fine but there is a type error of string is not assigned to undefined and not sure why it is saying this.

I am getting the same issue.

samthompsonkennedy avatar Jul 31 '23 23:07 samthompsonkennedy

Bump on this, also experiencing the same issue

jourdanhaines avatar Aug 06 '23 23:08 jourdanhaines

@gascenciom1998 I did some digging and in your case this seems to actually be a model naming issue. I think that List in a model name can somehow lead to conflicts because prisma generates types , where List is appended to the model name, whenever this model is somewhere used as a list relation.

in your provided schema prisma generates two types with the name ProductListRelationFilter. One comes from the list relation in the Category model and the other from the relation to ProductList in the RefProductList model. The generator only replicates these types as schemas.

image

When you change the name of the ProductList model to e.g. ProductCollection the error goes away since there are no more naming collisions between types.

image

So please check for any model names that include List since it seems that this is a somewhat reserved name in prisma. Please report back if you still encounter this issue.

chrishoermann avatar Aug 07 '23 18:08 chrishoermann

Wow this seems to have worked thanks so much @chrishoermann

gascenciom1998 avatar Aug 08 '23 17:08 gascenciom1998