#ReferenceError: Must call super constructor in derived class before accessing 'this' or returning...

9 messages · Page 1 of 1 (latest)

wraith dust
#

Hi there! I am using Prisma ORM to use PostgreSQL. Whenever I try to update a value, I get the following error:

ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor
    at new PrismaClientValidationError (/Users/mdgaziurrahmannoor/Programming/Projects/simplyFi/simplify-backend/src/generated/prisma/runtime/library.js:24:2253)
    at kn (/Users/mdgaziurrahmannoor/Programming/Projects/simplyFi/simplify-backend/src/generated/prisma/runtime/library.js:32:1363)
    at Zn.handleRequestError (/Users/mdgaziurrahmannoor/Programming/Projects/simplyFi/simplify-backend/src/generated/prisma/runtime/library.js:124:7102)
    at Zn.handleAndLogRequestError (/Users/mdgaziurrahmannoor/Programming/Projects/simplyFi/simplify-backend/src/generated/prisma/runtime/library.js:124:6784)
    at Zn.<anonymous> (/Users/mdgaziurrahmannoor/Programming/Projects/simplyFi/simplify-backend/src/generated/prisma/runtime/library.js:124:6491)
    at Generator.throw (<anonymous>)
    at rejected (/Users/mdgaziurrahmannoor/Programming/Projects/simplyFi/simplify-backend/src/generated/prisma/runtime/library.js:8:65)

The function that updates the value:

import { PrismaClient } from "../generated/prisma";

export const PRISMA_CLIENT = new PrismaClient();

export async function updateWalletBalance(
  wallet_id: string,
  new_balance: number,
) {
  return PRISMA_CLIENT.wallet.update({
    where: {
      id: wallet_id,
    },
    data: {
      balance: new_balance,
    },
  });
}

Wallet table:

model Wallet {
  id               String          @id @default(uuid(4))
  name             String          @db.VarChar(64)
  balance          Float           @default(0) @db.DoublePrecision
  currency         String          @db.VarChar(3)
  transactions     Transaction[]
  User             User            @relation(fields: [userId], references: [id], onDelete: Cascade)
  userId           String
  WalletCategory   WalletCategory? @relation(fields: [walletCategoryId], references: [id])
  walletCategoryId String?
  Alert            Alert[]
}
wanton onyxBOT
#

Skipping coffee for instant knowledge! Let's brew that AI answer now.

wanton onyxBOT
# wanton onyx Skipping coffee for instant knowledge! Let's brew that AI answer now.

The error message “ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor” is not a typical Prisma error, but rather a JavaScript/TypeScript class inheritance issue. However, in the context of Prisma, this error can sometimes be triggered if there is a problem with how the Prisma Client is generated, imported, or used.

Based on the knowledge sources, similar PrismaClientValidationError issues have been reported when:

  • The Prisma Client import path is incorrect or the generated client is not up-to-date with your schema. For example, importing from a wrong path or from a folder that does not contain the generated client can cause runtime errors. Double-check that your import path matches the generated client location and that you have run prisma generate after any schema changes. See related import issues and solutions in this discussion and this issue.
  • There is a mismatch between the Prisma Client version and the generated files, or the client was not regenerated after a dependency update or schema change. Always run npx prisma generate after updating your schema or Prisma version.
  • The Prisma Client is not being instantiated correctly, or there are issues with the environment (e.g., running in an unsupported runtime or bundler).

What you should do:

  1. Ensure your import path is correct and points to the generated Prisma Client.
  2. Run npx prisma generate to regenerate the client.
  3. Make sure your Prisma Client and @prisma/client versions match.
  4. If you are using a monorepo or custom output directory, double-check the path and build steps.

If the problem persists after these steps, please provide more details about your project structure and Prisma setup. The knowledge sources do not contain a direct match for your exact error, but these steps address the most common cause

wanton onyxBOT
wanton onyxBOT
wraith dust
#

Node version: 23.11.0

gritty hazel
#

Hey!

As a quick test, can you remove output path from your schema.prisma file, regenerate Prisma Client in default location and check if you get the same error?

wraith dust
#

That fixed the error, thanks! I was passing an invalid type to Prisma, but instead of showing the proper error I was getting the aforementioned gibberish. Should I use the default path instead of generated one?

gritty hazel
#

Yes, please continue using the generated path