[BUG] Cannot read properties of undefined (reading 'map')
Describe the bug
I would love to use this, but I get this error when generating, and nothing else: Cannot read properties of undefined (reading 'map')
I have no idea how to investigate. How could I get more debug info? Cheers! 🙏
Package versions (please complete the following information):
- zod: 3.24.2
- prisma: 5.16.1
Context:
// Generates Prisma JS Client types
generator client {
binaryTargets = ["native", "linux-arm64-openssl-1.1.x", "linux-arm64-openssl-3.0.x", "debian-openssl-1.1.x", "debian-openssl-3.0.x"]
previewFeatures = ["fullTextSearch", "postgresqlExtensions"]
provider = "prisma-client-js"
}
// Generate prisma schema in zod format
generator zod {
provider = "zod-prisma-types"
output = "../generated/zod"
}
model User {
id Int @id @default(autoincrement())
email String @unique
name String
timestamp DateTime
I've encountered the same error message Cannot read properties of undefined (reading 'map') when generating schemas after upgrading a project to use the latest version of zod-prisma-types. It occurs with all 3.2.x versions, starting with 3.2.0. Everything works as expected when using ~3.1.0.
Looks like the immediate cause is in ExtendedDMMFDatamodel._getExtendedIndexes. The indexes argument is undefined when it's called here: https://github.com/chrishoermann/zod-prisma-types/blob/7c173cb63921a1e7b782f911891113941374f8a0/packages/generator/src/classes/extendedDMMFDatamodel.ts#L30
This isn't causing any type errors because Prisma's DMMF.Datamodel type is defined as:
type Datamodel = ReadonlyDeep<{
models: Model[];
enums: DatamodelEnum[];
types: Model[];
indexes: Index[];
}>;
But this is only the case in Prisma 6! In Prisma 5, which both @CamilleHbp and I are using, the same type is defined as:
interface Datamodel {
models: Model[];
enums: DatamodelEnum[];
types: Model[];
}
That would track with the issue only occurring on releases that include bc1d97c0a4014db87139db8843c349fbc15b4d3e, which introduced support for Prisma 6.
When I replace the function in question with this, the generator works again:
_getExtendedIndexes(indexes) {
if (this.generatorConfig.prismaVersion.major < 6) {
return [];
}
return indexes.map((elem) => new extendedDMMFIndex_1.ExtendedDMMFIndex(this.generatorConfig, elem));
}
The interesting caveat is that the Prisma version detection doesn't work out-of-the-box on RedwoodJS projects because Prisma is brought in as a dependency of their CLI package rather than being listed in package.json, so I had to temporarily hardcode it to test it out. It might be an idea to check for node_modules/prisma/package.json as a fallback if Prisma isn't listed in the main package.json.
I'm happy to raise a PR for either/both of those if it would help! I'm hesitant to just dive into the first part without understanding what the indexes are used for (or will be used for) in zod-prisma-types. I don't want to create future headaches with a well-intentioned patch!
The same problem with: zod: 3.21.4 prisma: 5.5.2
Same issue here
"zod-prisma-types": "^3.2.4"
"zod": "^3.22.4"
"prisma": "^5.3.1",