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

error TS2300: Duplicate identifier when referencing the same enum twice in a model #109

Open
chrisui opened this issue Apr 21, 2022 · 6 comments

Comments

@chrisui
Copy link

chrisui commented Apr 21, 2022

We get a TS error due to duplicated named imports.

This schema:

enum MyEnum {
  A
  B
}

enum MyOtherEnum {
  A
  B
}

model MyModel {
  id String @id
  a MyEnum[]
  b MyOtherEnum?
  c MyEnum[]
  d MyOtherEnum?
}

Generates the following which results in the TS error

import {MyEnum, MyOtherEnum, MyEnum, MyOtherEnum} from '@prisma/client'
% npm ls zod-prisma
@gaia-family/monorepo@0.1.0 /Users/chrispearce/Projects/monorepo
└── zod-prisma@0.5.4

Desired:

Imported identifier should only be written once.

@chrisui
Copy link
Author

chrisui commented Apr 21, 2022

I think the problem is the following line which should probably be a unique set based on the identifier.

https://github.com/CarterGrimmeisen/zod-prisma/blob/main/src/generator.ts#L47

@MatthiasDunker
Copy link

I made a pull request for this.
Had the same issue.

#122

@SamSokolin
Copy link

@CarterGrimmeisen any chance you can release this fix to npm? Looks like f3c27fb fixes the issue but the most recent version on npm is from 6 months ago. Appreciate your work on this project, this is awesome!

@hiramhuang
Copy link

Running into the same issue here.

My temporary workaround is to generate Zod schema on my dev environment, fix errors & comment out the generator before git commit. (If you don't comment out the generator, the generated file will be overridden during npm install or prisma generate.)

@testerez
Copy link

testerez commented Nov 18, 2022

Until @MatthiasDunker 's fix gets deployed, you can install my fork (works for me):

yarn add testerez/zod-prisma

@soheil-bottleneck
Copy link

I'm having the same issue. Any update when the npm release will be updated? :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants