Repository navigation
Error when trying to generate seed #29110
Replies: 3 comments 4 replies
|
Hey @gabrieljun56! This is a common issue when working with Prisma. The error message is telling you exactly what to do — the Prisma Client hasn't been generated yet. Quick fix: Run this command before seeding: npx prisma generateThen run your seed command: npx prisma db seedWhy this happens: Since you have a custom output path ( import { PrismaClient } from '../app/src/generated/prisma'Pro tip for your workflow: You can combine commands in your "prisma": {
"seed": "npx prisma generate && ts-node prisma/seed.ts"
}This ensures generate always runs before seed. Also, if you're writing complex SQL queries alongside Prisma, tools like ai2sql.io can help you convert natural language to SQL — useful for debugging or creating raw queries when needed. Let me know if this helps! 🚀 |
SolutionThe error Fix 1: Import from your custom output pathYour schema has: output = "../app/src/generated/prisma"So in // ❌ Wrong
import { PrismaClient } from "@prisma/client";
// ✅ Correct - use your custom output path
import { PrismaClient } from "../app/src/generated/prisma";Fix 2: Run generate firstnpx prisma generate
npx prisma db seedFix 3: Use tsx instead of node for TypeScriptUpdate {
"prisma": {
"seed": "tsx prisma/seed.ts"
}
}Then install tsx: npm install -D tsxWhy this happensWhen you use a custom |
|
Please feel free to mark one the solutions as answers if your question is resolved. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Question
When I execute the command "npx prisma db seed", it returns the following error:
Loaded Prisma config from prisma.config.ts.
Running seed command
node ./prisma/seed.ts...C:\Users\Revionot\OneDrive\Desktop\finances-ts\node_modules@prisma\client\scripts\default-index.js:43
throw new Error('@prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.');
^
Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
at new PrismaClient (C:\Users\Revionot\OneDrive\Desktop\finances-ts\node_modules@prisma\client\scripts\default-index.js:43:11)
at file:///C:/Users/Revionot/OneDrive/Desktop/finances-ts/prisma/seed.ts:4:16
at ModuleJob.run (node:internal/modules/esm/module_job:345:25)
at async onImport.tracePromise.proto (node:internal/modules/esm/loader:665:26)
at async asyncRunEntryPointWithESMLoader (node:internal/modules/run_main:117:5)
Node.js v22.20.0
An error occurred while running the seed command:
Error: Command failed with exit code 1: node ./prisma/seed.ts
How to reproduce (optional)
Expected behavior (optional)
No response
Information about Prisma Schema, Client Queries and Environment (optional)
// Add any relevant Prisma Client queries hereAll reactions