prismix
prismix copied to clipboard
TypeError: Cannot read property 'length' of undefined
Hello,
got this error when run npx prismix
command. But don't know where it comes from. I am using nx for monorepo, the config json file:
{
"mixers": [
{
"input": [
"./prisma/base.prisma",
"./prisma/address.prisma",
"./prisma/authentication-method.prisma",
"./prisma/brand.prisma",
"./prisma/card.prisma",
"./prisma/channel.prisma",
"./prisma/comment.prisma",
"./prisma/country.prisma",
"./prisma/file.prisma",
"./prisma/like.prisma",
"./prisma/permission.prisma",
"./prisma/product.prisma",
"./prisma/promotion.prisma",
"./prisma/review.prisma",
"./prisma/role.prisma",
"./prisma/source.prisma",
"./prisma/user.prisma"
],
"output": "./prisma/schema.prisma"
}
]
}
and some example codes of the schema files, is that done correctly?
role.prisma
// Role
model Role {
id String @id @default(cuid())
/// @Validator.MaxLength(10)
name String
slug String @unique
/// @Validator.MaxLength(50)
description String?
/// @HideField({input:true, output:false})
status RoleStatus? @default(normal)
isDefault Boolean? @default(false)
channels Channel[]
createdAt DateTime @default(now())
updatedAt DateTime? @updatedAt
}
// ----------------------------------------------------------------
enum RoleStatus {
normal
terminated
}
model Channel {
id String @id @default(cuid())
Role Role? @relation(fields: [roleId], references: [id])
roleId String?
}
review.prisma
// Product review
model Review {
id String @id @default(cuid())
/// @Validator.IsInt()
/// @Validator.Min(1)
/// @Validator.Max(5)
rate Int
description String?
/// @Validator.MaxLength(3)
uploads File[]
}
// -----------
model File {
id String @id @default(cuid())
Review Review? @relation(fields: [reviewId], references: [id])
reviewId String?
}
file.prisma
model File {
id String @id @default(cuid())
name String
alt String?
title String?
caption String?
format FileType
mimeType String
size Bytes
width Int?
height Int?
source Source? @relation(fields: [sourceId], references: [id]) // a file has its source
sourceId String? @unique
autoPlay Boolean?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
customFields Json?
}
// -----
enum FileType {
// image
IMAGE
// video
VIDEO
// sound
SOUND
// other
BINARY
}
model Source {
id String @id @default(cuid())
File File[]
}
@jamiepine
This exception occurs in the function renderAttribute
at this line:
return idFields.length > 0 ?
@@id([${idFields.join(', ')}]) : '';
because idFields
is undefined. Looking up the stack a bit I see that the code expects there to be an idFields
property on the DMMF.Model
class, but there is none. I'm wondering if this is due a to version skew: i.e., prismix is based on an older definition of DMMF.Model
?
@blevine seems to be right., I did find this commit https://github.com/prisma/prisma/commit/c94f0e91bc0e87e4765a67dddd40a36251faae87 where idFields
has been renamed to primaryKey
For the people looking for a quick fix :
- Clone this repo
-
yarn install && yarn run build
- In your project run
yarn add file:/path/to/prismix
(only for yarn)
You should then be able to use prismix
I pushed a hotfix to prevent it erroring (1.0.18). Looking into Prisma's changes it isn't entirely clear how primaryKey
is supposed to replace idFields
as the only value of primaryKey
I can see is null
, will look into this further later.