P
Prisma•3d ago
Quazar

Problem creating a new user to my database

Hello so I'm using prisma and nodejs but I'm facing a little issue when I try to create a new user into my db. The error arises from here:
import prisma from "@/lib/prisma";

const newUser = await prisma.user.create({
data: {
id: evt.data.id!,
email: primaryEmail.email_address,
isSubscribed: false, // Default setting
},
});
import prisma from "@/lib/prisma";

const newUser = await prisma.user.create({
data: {
id: evt.data.id!,
email: primaryEmail.email_address,
isSubscribed: false, // Default setting
},
});
it says: Property 'user' does not exist on type 'PrismaClient<PrismaClientOptions, never, DefaultArgs>'.ts(2339) However I do have a User model in my prisma.scheme file and I have run the commands to generate it as well npx prisma generate and npx prisma migrate
3 Replies
Prisma AI Help
Prisma AI Help•3d ago
You opted for speed from this bot. Let's conjure up an answer right now! I can help you with this Prisma issue. The error "Property 'user' does not exist on type 'PrismaClient'" typically occurs when there's a mismatch between your Prisma schema and the generated client. Based on the knowledge sources, there are a few common solutions to this problem: 1. Check your model name casing The most likely issue is that your model name in the schema might be using a different case than what you're trying to access. In Prisma, if your model is defined as User (capital U), you should access it with lowercase in your code:
// Correct way
const newUser = await prisma.user.create({
// ...
});
// Correct way
const newUser = await prisma.user.create({
// ...
});
If you're using prisma.User.create() (with capital U), this would cause the error you're seeing. This is a common issue as mentioned in this discussion. 2. Regenerate the Prisma client Make sure you've properly generated the Prisma client after defining your schema:
npx prisma generate
npx prisma generate
3. Check your output path in schema.prisma Some users have resolved this by explicitly setting the output path in their schema.prisma file:
generator client {
provider = "prisma-client-js"
output = "../node_modules/.prisma/client"
}
generator client {
provider = "prisma-client-js"
output = "../node_modules/.prisma/client"
}
This solution was mentioned in this issue and has helped many users, especially those using package managers like pnpm. 4. Import PrismaClient correctly Make sure your import statement is correct:
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
If you're using a custom import path, ensure it's pointing to the correct location. If none of these solutions work, you might want to check if your schema has been properly migrated to the database with npx prisma migrate dev or npx prisma db push. Let me know if any of these solutions help resolve your issue! 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Quazar
QuazarOP•3d ago
I have also tried using this solution but it does not work
Nurul
Nurul•16h ago
Can you share your schema.prisma file and your @lib/prisma file, I would like to see how you are exporting the PrismaClient

Did you find this page helpful?