Recently, I've been working on a dashboard app using Prisma, Next.js, and supabase.
Encountering an issue with the EventChart model in schema.prisma, I decided to create a new model called EventAreaChart. However, after migrating and attempting to execute a get method, an error message stating that EventAreaChart is undefined popped up.
The specific error reads:
TypeError: Cannot read properties of undefined (reading 'findMany')
at GET (webpack-internal:///(rsc)/./app/api/eventChart/route.ts:18:55)
Here's the content of route.ts file:
import { NextResponse } from "next/server"
import { main } from "../route"
import { PrismaClient } from "@prisma/client"
const prisma = new PrismaClient
export const GET = async (req: Request, res: NextResponse ) => {
try {
await main()
const eventData = await prisma.eventAreaChart.findMany({
select: {
date: true,
userId: true,
actual: true,
expected: true,
}
})
return NextResponse.json({ message: "Success", eventData }, {status: 200})
} catch (err) {
console.error('Error in GET method:', err);
return NextResponse.json({ message: "Error", err }, {status: 500})
} finally {
await prisma.$disconnect()
}
}
Now taking a look at schema.prisma:
// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "postgresql"
url = env("DATABASE_URL")
directUrl = env("DIRECT_DATABASE_URL")
}
model User {
// User model details here...
}
// Other model definitions follow...
Attempting to retrieve data in a different setup:
"use client"
import { useState, useEffect } from 'react';
// Additional React component logic goes here...
export default EventAreaChart
Troubleshooting steps taken so far: - Restarted supabase - Migrated database after adding EventAreaChart model
If anyone could provide assistance, it would be greatly appreciated.