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

[BUG] Unused import type { Prisma } from './client incompatible with verbatimModuleSyntax is being generated #273

Open
kran6a opened this issue Aug 31, 2024 · 0 comments
Assignees
Labels
bug (unconfirmed) Could be a bug

Comments

@kran6a
Copy link

kran6a commented Aug 31, 2024

Describe the bug
When the index.ts is generated the start of the file looks like the following:

import { z } from 'zod';
import type { Prisma } from './client';

The second import is not only useless as the Prisma type is not used anywhere on the file but it is also incompatible with tsconfig option verbatimModuleSyntax as the ESM standard requires specifying the file extension so it should be import type { Prisma } from './client/index.js';

This makes code quality tools report an unused import and tsc to error due to verbatimModuleSyntax.

Package versions (please complete the following information):

  • zod: 3.23.8
  • prisma: 5.19.0

Additional context
Generators defined on my prisma schema:

generator client {
  provider        = "prisma-client-js"
  output          = "./client"
  previewFeatures = ["relationJoins", "nativeDistinct", "omitApi", "driverAdapters", "typedSql"]
}

generator zod {
  provider                         = "zod-prisma-types"
  output                           = "./entities" // (default) the directory where generated zod schemas will be saved
  useMultipleFiles                 = false // default is false
  writeBarrelFiles                 = true // default is true
  createModelTypes                 = true // default is true
  addInputTypeValidation           = true // default is true
  validateWhereUniqueInput         = true // default is false
  createOptionalDefaultValuesTypes = true // default is false
  createRelationValuesTypes        = true // default is false
  createPartialTypes               = true // default is false

  createInputTypes         = false // default is true
  addIncludeType           = false // default is true
  addSelectType            = false // default is true
  useDefaultValidators     = false // default is true
  coerceDate               = true // default is true
  writeNullishInModelTypes = true // default is false
  prismaClientPath         = "./client"
}

This can be easily fixed by changing lines 19 and 21 at https://github.com/chrishoermann/zod-prisma-types/blob/master/packages/generator/src/functions/writeSingleFileImportStatements.ts

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug (unconfirmed) Could be a bug
Projects
None yet
Development

No branches or pull requests

2 participants