getting error "prisma:error Must call super constructor ..." at a simple insert

So, I get this error "prisma:error Must call super constructor in derived class before accessing 'this' or returning from derived constructor" when doing this insert:
const form = await prisma.forms.create({
data: formData
});
const form = await prisma.forms.create({
data: formData
});
The formData looks like this:
const formData = {
userId,
isComplete: false,
treatmentType: user?.treatmentType || TREATMENT_TYPE.TBD,
isArchived: false,
formType: 'Youth',
isCaregiver: !!isCaregiver,
...(sessionId && { sessionId })
};
const formData = {
userId,
isComplete: false,
treatmentType: user?.treatmentType || TREATMENT_TYPE.TBD,
isArchived: false,
formType: 'Youth',
isCaregiver: !!isCaregiver,
...(sessionId && { sessionId })
};
And the model in schema has all those fields and then some The prisma variable seems to be instantiated&configured correctly, because this query, which is in the same function, above the erroring one, returns successfully:
const user = await prisma.users.findUnique({
where: { id: userId }
});
const user = await prisma.users.findUnique({
where: { id: userId }
});
. Now github's copilot and gemini from Microsoft couldn't come up with a working solution/workaround, and neither did google search results. My environment: Node 22.14, Prisma:
npx prisma -v
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
prisma : 6.12.0
@prisma/client : 6.12.0
Computed binaryTarget : debian-openssl-1.1.x
Operating System : linux
Architecture : x64
Node.js : v22.14.0
TypeScript : 5.8.3
Query Engine (Node-API) : libquery-engine 8047c96bbd92db98a2abc7c9323ce77c02c89dbc (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
PSL : @prisma/prisma-schema-wasm 6.12.0-15.8047c96bbd92db98a2abc7c9323ce77c02c89dbc
Schema Engine : schema-engine-cli 8047c96bbd92db98a2abc7c9323ce77c02c89dbc (at node_modules/@prisma/engines/schema-engine-debian-openssl-1.1.x)
Default Engines Hash : 8047c96bbd92db98a2abc7c9323ce77c02c89dbc
Studio : 0.511.0
npx prisma -v
Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma
prisma : 6.12.0
@prisma/client : 6.12.0
Computed binaryTarget : debian-openssl-1.1.x
Operating System : linux
Architecture : x64
Node.js : v22.14.0
TypeScript : 5.8.3
Query Engine (Node-API) : libquery-engine 8047c96bbd92db98a2abc7c9323ce77c02c89dbc (at node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node)
PSL : @prisma/prisma-schema-wasm 6.12.0-15.8047c96bbd92db98a2abc7c9323ce77c02c89dbc
Schema Engine : schema-engine-cli 8047c96bbd92db98a2abc7c9323ce77c02c89dbc (at node_modules/@prisma/engines/schema-engine-debian-openssl-1.1.x)
Default Engines Hash : 8047c96bbd92db98a2abc7c9323ce77c02c89dbc
Studio : 0.511.0
Do you have any ideas what could be wrong or how I can fix this?
3 Replies
Prisma AI Help
Prisma AI Help2mo ago
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into #ask-ai for a quick spin!
Nurul
Nurul2mo ago
The error message you are seeing is not a Prisma specific error. This typically occurs when you have a class that extends another class and you try to use this before calling super() in the constructor. Have you extended the PrismaClient class anywhere in your codebase?
tudor galt
tudor galtOP2mo ago
Thanks for coming back to me. No, I didn't extend the Prisma class, nor did I do any advanced or complicated operations with the instance. This is how I instantiate it:
const sequelize = new Sequelize(
process.env.PGDATABASE || 'my_db',
process.env.PGUSER || 'postgres',
process.env.PGPASSWORD || '12345',
{
host: process.env.PGHOST || 'localhost',
dialect: 'postgres',
port: process.env.PGPORT || "5432",
}
);

// For development, store in global to prevent multiple instances during hot reloading
let prisma = null;
try {
// Import from the custom generated location
const prismaLogOptions = ['query', 'info', 'warn', 'error'];

if (process.env.NODE_ENV === 'development') {
if (!global.prisma) {
global.prisma = new PrismaClient({ log: prismaLogOptions });
}
prisma = global.prisma;
} else {
prisma = new PrismaClient({ log: prismaLogOptions });
}

console.log('Prisma client initialized successfully');
} catch (error) {
console.error('Failed to initialize Prisma client:', error.message);
console.log('Please check path to generated Prisma client');
}

module.exports.prisma = prisma;
const sequelize = new Sequelize(
process.env.PGDATABASE || 'my_db',
process.env.PGUSER || 'postgres',
process.env.PGPASSWORD || '12345',
{
host: process.env.PGHOST || 'localhost',
dialect: 'postgres',
port: process.env.PGPORT || "5432",
}
);

// For development, store in global to prevent multiple instances during hot reloading
let prisma = null;
try {
// Import from the custom generated location
const prismaLogOptions = ['query', 'info', 'warn', 'error'];

if (process.env.NODE_ENV === 'development') {
if (!global.prisma) {
global.prisma = new PrismaClient({ log: prismaLogOptions });
}
prisma = global.prisma;
} else {
prisma = new PrismaClient({ log: prismaLogOptions });
}

console.log('Prisma client initialized successfully');
} catch (error) {
console.error('Failed to initialize Prisma client:', error.message);
console.log('Please check path to generated Prisma client');
}

module.exports.prisma = prisma;
This is getting weirder: I have this code snippet, which throws that error at the last .findMany, all the others working normally:
const populateUpcomingElementTable = async function (userId, treatmentPlan, checkAdditional = false) {
try {
const getTreatmentPlan = await prisma.treatmentPlans.findFirst({
where: { name: treatmentPlan }
});

const getElementRelations = await prisma.treatmentElementRelations.findMany({
where: { treatmentPlanId: getTreatmentPlan.id },
orderBy: { order: 'asc' }
});

const getElementsFromUserRelation = await prisma.userElementRelations.findMany({
where: { userId }
});

const userRelationElementIds = getElementsFromUserRelation.map(el => el.elementId);
let elementIds1 = getElementRelations.map(el => el.elementId);

if(checkAdditional){
elementIds1 = [...elementIds1, 59, 60, 61, 62];
}

const elementIds = excludeExistingElements(elementIds1, userRelationElementIds);

const finishedElementsByRec = await prisma.finishedElementsByRecommandations.findMany({
where: { userId }
});

const finishedElements = await prisma.treatmentPlanElements.findMany({
where: { id: { in: finishedElementsByRec.map(el => el.elementId) } }
});

// Create a set of finished element names for deduplication
const finishedElementNames = new Set(finishedElements.map(el => el.name));

// Fetch elements from the database for the treatment plan
const elements = await prisma.treatmentPlanElements.findMany({
where: {
elementId: { in: elementIds }
}
});
const populateUpcomingElementTable = async function (userId, treatmentPlan, checkAdditional = false) {
try {
const getTreatmentPlan = await prisma.treatmentPlans.findFirst({
where: { name: treatmentPlan }
});

const getElementRelations = await prisma.treatmentElementRelations.findMany({
where: { treatmentPlanId: getTreatmentPlan.id },
orderBy: { order: 'asc' }
});

const getElementsFromUserRelation = await prisma.userElementRelations.findMany({
where: { userId }
});

const userRelationElementIds = getElementsFromUserRelation.map(el => el.elementId);
let elementIds1 = getElementRelations.map(el => el.elementId);

if(checkAdditional){
elementIds1 = [...elementIds1, 59, 60, 61, 62];
}

const elementIds = excludeExistingElements(elementIds1, userRelationElementIds);

const finishedElementsByRec = await prisma.finishedElementsByRecommandations.findMany({
where: { userId }
});

const finishedElements = await prisma.treatmentPlanElements.findMany({
where: { id: { in: finishedElementsByRec.map(el => el.elementId) } }
});

// Create a set of finished element names for deduplication
const finishedElementNames = new Set(finishedElements.map(el => el.name));

// Fetch elements from the database for the treatment plan
const elements = await prisma.treatmentPlanElements.findMany({
where: {
elementId: { in: elementIds }
}
});
when querying by id, it works:
const elements = await prisma.treatmentPlanElements.findMany({
where: {
id: { in: elementIds }
}
});
const elements = await prisma.treatmentPlanElements.findMany({
where: {
id: { in: elementIds }
}
});
And the model for that table looks like this (it has the elementId column)
model treatmentPlanElements {
id Int @id @default(autoincrement())
name String @db.VarChar(255)
elementId String @db.VarChar(255)
createdAt DateTime @default(now()) @db.Timestamptz(6)
updatedAt DateTime @default(now()) @db.Timestamptz(6)
assertationOptions String? @db.VarChar(800)
subText String? @db.VarChar(800)
finishedSteps finishedSteps[]
homeworkSteps homeworkSteps[]
steps steps[]
subElements subElements[]
treatmentElementRelations treatmentElementRelations[]
upcomingElements upcomingElements[]
userElementRelationOnSubmits userElementRelationOnSubmits[]
}
model treatmentPlanElements {
id Int @id @default(autoincrement())
name String @db.VarChar(255)
elementId String @db.VarChar(255)
createdAt DateTime @default(now()) @db.Timestamptz(6)
updatedAt DateTime @default(now()) @db.Timestamptz(6)
assertationOptions String? @db.VarChar(800)
subText String? @db.VarChar(800)
finishedSteps finishedSteps[]
homeworkSteps homeworkSteps[]
steps steps[]
subElements subElements[]
treatmentElementRelations treatmentElementRelations[]
upcomingElements upcomingElements[]
userElementRelationOnSubmits userElementRelationOnSubmits[]
}

Did you find this page helpful?