21

I'm working on ReactJS project with NextJS Framework and Prisma to manage connection and queries to the DB.

On my local project the Support model is found and when I use it in my API and build my project it's ok.

But when I push my project on production server (Plesk), the build shows me this typescript error because it doesn't find the Support model:

./src/pages/api/support/index.ts:27:26
Type error: Property 'support' does not exist on type 'PrismaClient<PrismaClientOptions, never, RejectOnNotFound | RejectPerOperation | undefined>'.

The path ./src/pages/api/support/index.ts is where I want to use the Support model

My prisma.schema:

datasource db {
  provider = "mysql"
  url      = env("DATABASE_CONNECTION")
}

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

model User {
  id              Int       @id @unique @default(autoincrement())
  gender          String?
  firstName       String
  lastName        String
  email           String    @unique
  phone           String
  birthday        DateTime?
  income          Float?
  pincode         Int?
  points          Float?
  token           String    @db.Text
  ipAddress       String
  kyc             Kyc[]
  createdAt       DateTime  @default(now())
  updatedAt       DateTime?
  isValidated     Boolean   @default(false)
  roleId          Int
  role            Role      @relation(fields: [roleId], references: [id])
  Alerts          Alerts[]
  Support Support[]
}

model Kyc {
  id        Int       @id @unique @default(autoincrement())
  name      String
  validated Boolean   @default(false)
  path      String
  createdAt DateTime  @default(now())
  updatedAt DateTime? @updatedAt
  user      User      @relation(fields: [userId], references: [id])
  userId    Int
}

model Alerts {
  id         Int      @id @unique @default(autoincrement())
  type       TYPE     @default(NOBLOCKED)
  message    String   @db.Text
  transferId Int      @unique
  fromUserId Int
  read       Boolean  @default(false)
  createdAt  DateTime @default(now())
  user       User     @relation(fields: [fromUserId], references: [id])
}

model Role {
  id   Int    @id @unique @default(autoincrement())
  name String
  User User[]
}

model Support {
  id        Int     @id @unique @default(autoincrement())
  subject   String
  message   String  @db.Text
  createdAt DateTime  @default(now())
  userId          Int
  user            User      @relation(fields: [userId], references: [id])
}

enum TYPE {
  BLOCKED
  NOBLOCKED
}

I don't know if I need to use prisma migrate dev or prisma migrate deploy each time I push the latest changes.

Peter
  • 263
  • 1
  • 3
  • 7
  • 5
    Did you ran `prisma generate` to generate Prisma client after making changes on Prisma schema ? `prisma migrate dev` will also generate Prisma client along with migration. – Pasindu Dilshan Sep 22 '21 at 05:38
  • 1
    In addition to what @PasinduDilshan mentioned (which is a likely cause of the problem), is this issue only with the Support model? Do all other models work as expected? – Tasin Ishmam Sep 22 '21 at 08:53
  • 1
    @TasinIshmam yes every other models worked properly. This error has been only for Support model because I had already pushed news models to the production server and I never had this type of error. This could be because I just started to use ```prisma migrate deploy``` with this Support model. And this is exactly what @Pasindudilshan said with the ```prisma migrate dev``` which also generates Prisma client and why I never had this error before. – Peter Sep 23 '21 at 08:07
  • 4
    Yes, ```prisma migrate deploy``` does not generate the client, so you have to run ```prisma generate``` as was mentioned. Just to clarify, you have been able to solve the problem now? – Tasin Ishmam Sep 23 '21 at 09:33
  • 1
    Yes everything works fine ! Thanks you guys for your help ! – Peter Sep 24 '21 at 12:16
  • Also If you use VS Code sometimes you need to restart TS server,, – Ahmed AlSaeed Sep 30 '21 at 07:51
  • 1
    If anyone has this issue in WebStrom/IntelliJ: add a new JS library pointing to `node_modules/@prisma/client` in IDE settings (Languages & Frameworks -> JavaScript -> Libraries -> Add...) – ivanjermakov Jun 01 '22 at 18:27

13 Answers13

78

I tried prisma generate and prisma migrate dev but was still having the same error. I had to restart VSCode and everything is working fine now

Eric Mabo
  • 850
  • 5
  • 4
  • 1
    This worked for me too. Thanks for the note, I *never* would have guessed this. – wilk Jun 04 '22 at 13:43
  • This surprisingly solved the problem – piggybox Nov 06 '22 at 17:33
  • 10
    If you are using Typescript, open up the Command Palette (Ctrl Shift P), and typing "Restart Typescript Server", and press enter. Would help as well, without the need to restart VSCode – monkfromearth Dec 07 '22 at 07:09
  • I remember that I had the same problem and fixed it with that, but now it doesn't work anymore on any device after restarts and it won't build, so not a vscode issue this time. What now?? – france1 Mar 10 '23 at 14:36
  • This worked for me too. Thks – Jean Vidal Mar 22 '23 at 10:23
  • this was also the solution for nvim – shredGnar Apr 10 '23 at 20:20
  • running $ prisma generate worked for me. I read through the documentation and ideally prisma generate should be executed every time you make changes in the prisma.schema file. Here's the reference https://www.prisma.io/docs/concepts/components/prisma-client#:~:text=4.%20Evolving%20your%20application – Lea Tinoso Apr 27 '23 at 15:03
  • surprisingly it works – Ángel Ugarte May 20 '23 at 17:17
5

I forgot to await

const user = prisma.user.findUnique({ 
  where: {
    userId: authorUserId
  },
  select: {
    id: true
  }
})

but should be:

const user = **await** prisma.user.findUnique({ 
  where: {
    userId: authorUserId
  },
  select: {
    id: true
  }
})
Adamokkha
  • 149
  • 1
  • 3
4

Restart your typescript server in VSCode CTRL + SHIFT + P then type: restart TS Server

Fadi Nouh
  • 324
  • 2
  • 12
3

I have restarted my Visual Studio code and it started working fine.

venky royal
  • 1,860
  • 2
  • 11
  • 19
2

used prisma generate command but still, the schemas were marked as red. I had to restart my web storm IDE to get it fixed.

PKS
  • 618
  • 1
  • 7
  • 19
1

I tried everything, even reinstalling prisma client. What worked for me was recreating the migration.

1

Simply open the file ./node_modules/.prisma/client/index.d.ts.

This file contains the types generated. Opening it instantly triggers typescript to update those types.

Raymundus
  • 2,173
  • 1
  • 20
  • 35
1

Try to run npx prisma generate. The model should then be in the prisma client. However if not, try ctrl + P then type in > reload window in the vs code command palette and hit the reload window option. That should solve the issue

TeeBeeGee
  • 89
  • 1
  • 3
1

I made a silly mistake by extending PrismaClient class in

prisma.module.ts

export class PrismaModule extends PrismaClient {}

prisma.service.ts

@Injectable()
export class PrismaService extends PrismaClient {}
mac-deep
  • 41
  • 5
0

In my case, I created a schema named Post, but I called await prisma.posts. It should be called await prisma.posts. Make sure you don't make Typo.

Dibas Dauliya
  • 639
  • 5
  • 20
0

Note! I'm only refer to the title of the question and not to the content. This error also can be raised also when you don't working with the right node version like in situation when using nvm with old node version.

Eran Or
  • 1,252
  • 15
  • 22
0

Just Restart VSCode, it works magic!!!.

if above solution not worked, try this solution

saigopi.me
  • 14,011
  • 2
  • 83
  • 54
0

My issue was that the prisma client references the model names but as camelCase, whereas they're defined in the schema using PascalCase. This threw me because most of my model names are single words so where I'd defined a model name like User in the schema and added @@map("user") to the definition, I had the impression that when I did something like await prisma.user.delete({ ... the model/ table name user was lowercase as a result of the @@map declaration, but it turns out it isn't, rather prisma takes the model name and makes the first letter lowercase, and hence why for my model name OTP (with @@map("otp)) I have to use it like prisma.oTP.delete({ ...

wkille
  • 543
  • 6
  • 12