zenstack icon indicating copy to clipboard operation
zenstack copied to clipboard

`zenstack generate`: Error compiling generated code

Open reznakt opened this issue 5 months ago • 5 comments

Description and expected behavior

When running zenstack generate, the generation fails during the "Generating Zod schemas" phase with the following error:

Error compiling generated code:
../../node_modules/zod/v4/classic/schemas.d.cts:455:31 - error TS1139: Type parameter declaration expected.

455 export declare function union<const T extends readonly core.SomeType[]>(options: T, params?: string | core.$ZodUnionParams): ZodUnion<T>;
                                  ~~~~~
../../node_modules/zod/v4/classic/schemas.d.cts:455:39 - error TS1005: ',' expected.

455 export declare function union<const T extends readonly core.SomeType[]>(options: T, params?: string | core.$ZodUnionParams): ZodUnion<T>;
                                          ~~~~~~~
../../node_modules/zod/v4/classic/schemas.d.cts:455:56 - error TS1005: ',' expected.

455 export declare function union<const T extends readonly core.SomeType[]>(options: T, params?: string | core.$ZodUnionParams): ZodUnion<T>;
                                                           ~~~~
../../node_modules/zod/v4/classic/schemas.d.cts:455:60 - error TS1005: ',' expected.

455 export declare function union<const T extends readonly core.SomeType[]>(options: T, params?: string | core.$ZodUnionParams): ZodUnion<T>;
                                                               ~
../../node_modules/zod/v4/classic/schemas.d.cts:455:69 - error TS1005: ',' expected.

455 export declare function union<const T extends readonly core.SomeType[]>(options: T, params?: string | core.$ZodUnionParams): ZodUnion<T>;
                                                                        ~
../../node_modules/zod/v4/classic/schemas.d.cts:455:71 - error TS1005: ',' expected.

455 export declare function union<const T extends readonly core.SomeType[]>(options: T, params?: string | core.$ZodUnionParams): ZodUnion<T>;
                                                                          ~
../../node_modules/zod/v4/classic/schemas.d.cts:455:80 - error TS1005: ')' expected.

455 export declare function union<const T extends readonly core.SomeType[]>(options: T, params?: string | core.$ZodUnionParams): ZodUnion<T>;
                                                                                   ~
../../node_modules/zod/v4/classic/schemas.d.cts:455:92 - error TS1109: Expression expected.

455 export declare function union<const T extends readonly core.SomeType[]>(options: T, params?: string | core.$ZodUnionParams): ZodUnion<T>;
                                                                                               ~
../../node_modules/zod/v4/classic/schemas.d.cts:455:123 - error TS1005: ';' expected.

455 export declare function union<const T extends readonly core.SomeType[]>(options: T, params?: string | core.$ZodUnionParams): ZodUnion<T>;
                                                                                                                              ~
../../node_modules/zod/v4/classic/schemas.d.cts:455:124 - error TS1128: Declaration or statement expected.

455 export declare function union<const T extends readonly core.SomeType[]>(options: T, params?: string | core.$ZodUnionParams): ZodUnion<T>;
                                                                                                                               ~

: Error compiling generated code

Environment (please complete the following information):

  • Bun version: 1.2.18
  • ZenStack version: 2.16.1
  • Prisma version: 6.11.1
  • Database type: PostgreSQL

Additional context

I have managed to reproduce the error with code as minimal as this:

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

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

model User {
  id        Int    @id @default(autoincrement())
  firstName String @length(1, 50)
}

It appears that any use of the zod plugin results in this error. When the @length(1, 50) constraint is removed, the plugin is disabled and everything works just fine.

reznakt avatar Jul 19 '25 21:07 reznakt

I tried disabling TypeScript compilation by using

plugin zod {
  provider = "@core/zod"
  compile = false
}

which did not help. However, using

zenstack generate --no-compile

seems to fix the issue.

I'm not sure if I did something wrong with the plugin settings; after reading the docs, I thought that compile = true should be identical to --no-compile, but that doesn't seem to be the case here.

reznakt avatar Jul 19 '25 21:07 reznakt

Hi @reznakt , thanks for filing it. I couldn't reproduce it with a simple project. Could you share a repro please?

ymc9 avatar Jul 25 '25 00:07 ymc9

I have ran --no-compile as well. However, afterwards enhance client wasn't available. Switching back to Prisma 6.12.0 have seemed to fix the issue for me.

bigjohnn1 avatar Aug 04 '25 17:08 bigjohnn1

We upgraded ts-morph dependency version in release 2.18.0. Could you guys try it you still run into compilation issues?

ymc9 avatar Aug 11 '25 09:08 ymc9

Works fine now, thank you for the update. :) I think the issue can be closed now.

bigjohnn1 avatar Aug 14 '25 08:08 bigjohnn1