prisma / prisma

Next-generation ORM for Node.js & TypeScript | PostgreSQL, MySQL, MariaDB, SQL Server, SQLite, MongoDB and CockroachDB
https://www.prisma.io
Apache License 2.0
39.37k stars 1.54k forks source link

Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again. #18272

Open remycross1019 opened 1 year ago

remycross1019 commented 1 year ago

Bug description

Whenever I try to run my dev server, I get this error. I have tried to run prisma generate many time and reinstall all my dependencies but I still get the error.

How to reproduce

I run "npm run dev" I try to log into my server

Expected behavior

No response

Prisma information

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

model Account {
  id                String  @id
  userId            String
  type              String
  provider          String
  providerAccountId String
  refresh_token     String?
  access_token      String?
  expires_at        Int?
  token_type        String?
  scope             String?
  id_token          String?
  session_state     String?
  User              User    @relation(fields: [userId], references: [id], onDelete: Cascade)

  @@unique([provider, providerAccountId])
}

model Author {
  id   String @id
  name String
  Book Book[]
}

model Book {
  isbn            String     @id
  title           String
  publisher       String
  publicationYear Int
  dimensions      Float[]
  pageCount       Int?
  genreID         String
  retailPrice     Float
  inventory       Int        @default(0)
  authorNames     String
  imageLink       String?
  shelfSpace      Float?     @default(0)
  Genre           Genre      @relation(fields: [genreID], references: [id])
  Buyback         Buyback[]
  Purchase        Purchase[]
  Sale            Sale[]
  Author          Author[]
}

model BookBuybackOrder {
  id          String    @id
  vendorId    String
  date        DateTime
  revenue     Float     @default(0)
  totalBooks  Int       @default(0)
  uniqueBooks Int       @default(0)
  vendorName  String    @default("")
  Vendor      Vendor    @relation(fields: [vendorId], references: [id])
  Buyback     Buyback[]
}

model Buyback {
  id               String           @id
  quantity         Int
  buybackPrice     Float
  bookId           String
  buybackOrderId   String
  subtotal         Float            @default(0)
  Book             Book             @relation(fields: [bookId], references: [isbn])
  BookBuybackOrder BookBuybackOrder @relation(fields: [buybackOrderId], references: [id])
}

model Genre {
  id   String @id
  name String @unique
  Book Book[]
}

model Image {
  id       String @id
  publicId String @unique
  format   String
  version  String
}

model Purchase {
  id              String        @id
  quantity        Int
  price           Float
  bookId          String
  purchaseOrderId String
  subtotal        Float         @default(0)
  Book            Book          @relation(fields: [bookId], references: [isbn])
  PurchaseOrder   PurchaseOrder @relation(fields: [purchaseOrderId], references: [id])
}

model PurchaseOrder {
  id          String     @id
  vendorId    String
  date        DateTime
  cost        Float      @default(0)
  totalBooks  Int        @default(0)
  uniqueBooks Int        @default(0)
  vendorName  String     @default("")
  Purchase    Purchase[]
  Vendor      Vendor     @relation(fields: [vendorId], references: [id])
}

model Sale {
  id                   String             @id
  quantity             Int
  price                Float
  bookId               String
  saleReconciliationId String
  subtotal             Float              @default(0)
  Book                 Book               @relation(fields: [bookId], references: [isbn])
  saleReconciliation   saleReconciliation @relation(fields: [saleReconciliationId], references: [id])
}

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

model User {
  id            String    @id
  name          String?
  email         String?   @unique
  emailVerified DateTime?
  image         String?
  password      String
  role          Role      @default(USER)
  Account       Account[]
  Session       Session[]
}

model Vendor {
  id                    String             @id
  name                  String
  bookBuybackPercentage Float?             @default(0)
  BookBuybackOrder      BookBuybackOrder[]
  PurchaseOrder         PurchaseOrder[]
}

model VerificationToken {
  identifier String
  token      String   @unique
  expires    DateTime

  @@unique([identifier, token])
}

model saleReconciliation {
  id          String   @id
  date        DateTime
  revenue     Float    @default(0)
  totalBooks  Int      @default(0)
  uniqueBooks Int      @default(0)
  Sale        Sale[]
}

enum Role {
  USER
  ADMIN
  SUPERADMIN
}

Environment & setup

Prisma Version

4.11.0
pritam199902 commented 1 year ago

It looks like some how prisma client is not generated. It could be schema is not migrated yet. Can you please share your code dir structure?

daver987 commented 1 year ago

I am getting the same issue deploying on Vercel Everything was working totally fine, I pushed my PlanetScale DB to production, then everything went south. I'm using Nuxt 3

Screenshot 2023-03-13 at 9 48 49 PM

I also started getting '.prisma/client/index-browser' cannot be resolved,

Here is the repo if you want to take a quick look https://github.com/daver987/hpl-website-nuxt

daver987 commented 1 year ago

I was able to get this issue figured out, for some reason the paths changed or something changed maybe with an update. Here is what I used to resolve the issue. I added this into my Nuxt 3 config

vite: {
    resolve: {
      alias: { '.prisma/client/index-browser': `@prisma/client/index-browser` },
    },
  },
murphman300 commented 1 year ago

running into this

turned on a previewFeature, now all branches are deploying onto Google App Engine with the following error:

image

this error is thrown on initialization of PrismaClient, ie:

db = new PrismaClient();

For context, this was working perfectly fine before adding in the preview feature. nothing broke on local environment before running a deployment. We reverted the commit, and have tried for hours to deploy several unaffected branches.

Very confused why other branches would be affected by this as well. We've cleared about all caches we can think of. The prisma package has also been pinned for a couple of weeks now so we don't think it's a version issue with prisma. We've tried all pre/post install/build approaches as well.

@janpio @pritam199902 any ideas?

murphman300 commented 1 year ago

@janpio @pritam199902 circling back - we had to re-install prisma in order for this to work again..

rather odd solution, would you know why the node_modules path resolution might have broken after enabling a previewFeature?

janpio commented 1 year ago

No idea, sorry. If you can reproduce this in any way, please open a new issue and describe what happened.