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

Does not seem to work with T3 stack out of the box 🤔 #113

Closed
MichaelOren opened this issue Mar 26, 2023 · 5 comments
Closed

Does not seem to work with T3 stack out of the box 🤔 #113

MichaelOren opened this issue Mar 26, 2023 · 5 comments

Comments

@MichaelOren
Copy link
Contributor

Hey Chris,

Thanks for your work!

I can't seem to get it to work with a blank T3 stack out of the box

Outputted Prisma Schema
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "sqlite"
// NOTE: When using postgresql, mysql or sqlserver, uncomment the @db.Text annotations in model Account below
// Further reading:
// https://next-auth.js.org/adapters/prisma#create-the-prisma-schema
// https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference#string
url      = env("DATABASE_URL")
}

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

model Example {
id        String   @id @default(cuid())
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

// Necessary for Next auth
model Account {
id                String  @id @default(cuid())
userId            String
type              String
provider          String
providerAccountId String
refresh_token     String? // @db.Text
access_token      String? // @db.Text
expires_at        Int?
token_type        String?
scope             String?
id_token          String? // @db.Text
session_state     String?
user              User    @relation(fields: [userId], references: [id], onDelete: Cascade)

@@unique([provider, providerAccountId])
}

model Session {
id           String   @id @default(cuid())
sessionToken String   @unique
userId       String
expires      DateTime
user         User     @relation(fields: [userId], references: [id], onDelete: Cascade)
}

model User {
id            String    @id @default(cuid())
name          String?
email         String?   @unique
emailVerified DateTime?
image         String?
accounts      Account[]
sessions      Session[]
}

model VerificationToken {
identifier String
token      String   @unique
expires    DateTime

@@unique([identifier, token])
}

npm install works fine and outputs the zod schemas fine.

After running npm run build I get the following error:


❯ npm run build

> [email protected] build
> next build

info  - Loaded env from /Users/michaeloren/coding/test-zod-types/.env
info  - Linting and checking validity of types ..Failed to compile.

./prisma/generated/zod/index.ts:1911:14
Type error: Type 'ZodObject<{ select: ZodOptional<ZodType<AccountSelect, ZodTypeDef, AccountSelect>>; include: ZodOptional<ZodType<AccountInclude, ZodTypeDef, AccountInclude>>; data: ZodUnion<...>; }, "strict", ZodTypeAny, { ...; }, { ...; }>' is not assignable to type 'ZodType<AccountCreateArgs, ZodTypeDef, AccountCreateArgs>'.
  The types of '_type.data' are incompatible between these types.
    Type '(AccountCreateInput | AccountUncheckedCreateInput) & (AccountCreateInput | AccountUncheckedCreateInput | undefined)' is not assignable to type '(Without<AccountCreateInput, AccountUncheckedCreateInput> & AccountUncheckedCreateInput) | (Without<...> & AccountCreateInput)'.
      Type 'AccountCreateInput & AccountUncheckedCreateInput' is not assignable to type '(Without<AccountCreateInput, AccountUncheckedCreateInput> & AccountUncheckedCreateInput) | (Without<...> & AccountCreateInput)'.
        Type 'AccountCreateInput & AccountUncheckedCreateInput' is not assignable to type 'Without<AccountUncheckedCreateInput, AccountCreateInput> & AccountCreateInput'.
          Type 'AccountCreateInput & AccountUncheckedCreateInput' is not assignable to type 'Without<AccountUncheckedCreateInput, AccountCreateInput>'.
            Types of property 'userId' are incompatible.
              Type 'string' is not assignable to type 'undefined'.

  1909 | }).strict()
  1910 |
> 1911 | export const AccountCreateArgsSchema: z.ZodType<Prisma.AccountCreateArgs> = z.object({
       |              ^
  1912 |   select: AccountSelectSchema.optional(),
  1913 |   include: AccountIncludeSchema.optional(),
  1914 |   data: z.union([ AccountCreateInputSchema,AccountUncheckedCreateInputSchema ]),
info  - Linting and checking validity of types ...%

I have no idea how to debug this error 😅 , any help would be appreciated 🙏

Reproduction instructions

Run npm create t3-app@latest and follow the prompts, select all of the options (prisma, trpc, nextauth and tailwind)

Install this package (npm install zod-prisma-types)

npm i and then npm run build

@fotoflo
Copy link
Contributor

fotoflo commented Mar 26, 2023

im also running t3 and i got this error when installing in an existing repo:
Steps:
npm install zod-prisma-types

add to prisma schema

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

$ prisma db push
Debugger attached.
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
Datasource "db": MySQL database "db" at "127.0.0.1:3306"

The database is already in sync with the Prisma schema.

Running generate... (Use --skip-generate to skip the generators)
Error: Generator at zod-prisma-types could not start:

/bin/sh: zod-prisma-types: command not found

@chrishoermann
Copy link
Owner

@MichaelOren thanks for the report! There ist a known issue with the latest version of zod. See #98. which Version of zod ist currently installed in a blank t3 Stack? Maybe this ist the cause dir this Bug?

@chrishoermann
Copy link
Owner

@fotoflo This seems to bei some other bug. I'll look into it.

@MichaelOren
Copy link
Contributor Author

Thanks for the quick response!

This is from the package.json

    "zod": "^3.21.4",
    "zod-prisma-types": "^2.5.1"

Confirmed rolling back to zod to 3.21.1 got it working 😄

Closing this issue as duplicate of 98

@aronmal
Copy link

aronmal commented Apr 24, 2023

Rolling back zod to 3.21.1 helped me too. Looking forward for the fix of #98, but so far I am very pleased by this package and it helps a lot.

I also just noticed the known issues reference in the Readme.md, but I missed it the first time and found this issue first.

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

4 participants