npx prisma db seed stops with 'Command failed with exit code 1'
Error: Command failed with exit code 1: ts-node --compiler-options {"module":"CommonJS"} prisma/seed.tsShort answer
That message only says your seed command returned exit code 1. Prisma runs whatever command you configured and reports its failure, so the real error is in your seed script. Run the same file directly with tsx to see it. In Prisma 7 the usual causes are a missing driver adapter or a seed command set in the wrong place.
Fix it fast
1Find out which cause you have
Prisma only forwards the exit code. Run the seed file by itself so the real error prints, instead of being hidden behind the wrapper message.
npx tsx prisma/seed.ts2Match what you see, then jump to its fix
- 1
The direct run prints a stack trace (a failed query, a unique constraint, a missing env value)The seed script itself throws and exits with 1Fix - 2
The direct run fails while constructing PrismaClientPrismaClient is created without a driver adapter (Prisma 7)Fix - 3
Nothing seeds, or the seed command is missing from prisma.config.tsThe seed command is not set where Prisma 7 reads itFix
- 1
What does the error look like?
Error: Command failed with exit code 1: ts-node --compiler-options {"module":"CommonJS"} prisma/seed.tsnpx prisma db seed
Cause 1 of 3
The seed script itself throws and exits with 1
1Check
Prisma's docs describe the seed value as any command that prisma db seed executes as given, so exit code 1 comes from your script. A typical seed file catches errors, disconnects and calls process.exit(1).
npx tsx prisma/seed.ts
echo "exit code: $?"2Fix
Fix the error the direct run shows. Keep the catch handler that disconnects the client and exits with 1, so a real failure still fails the command.
main()
.then(async () => {
await prisma.$disconnect()
})
.catch(async (e) => {
console.error(e)
await prisma.$disconnect()
process.exit(1)
})3Verify
Run the seed through Prisma again and read the exit code.
npx prisma db seed
echo "exit code: $?"Confirmed by prisma.io
Cause 2 of 3
PrismaClient is created without a driver adapter (Prisma 7)
1Check
In Prisma 7 the client must be initialised with a driver adapter. A seed file written for an older version calls new PrismaClient() with no arguments.
grep -n "new PrismaClient" prisma/seed.ts2Fix
Install the adapter packages and pass an adapter to the client, as the seeding guide shows for PostgreSQL.
npm i -D tsx @types/node @prisma/adapter-pg pg @types/pg dotenv3Verify
Run the seed file directly once more.
npx tsx prisma/seed.tsConfirmed by prisma.io
Cause 3 of 3
The seed command is not set where Prisma 7 reads it
1Check
Prisma 7 reads the seed command from the migrations block of prisma.config.ts. Seeding also no longer runs by itself after prisma migrate dev or migrate reset.
cat prisma.config.ts
grep -n "seed" package.json2Fix
Put the seed command in prisma.config.ts and run the seed yourself when you need it.
// prisma.config.ts
import "dotenv/config";
import { defineConfig, env } from "prisma/config";
export default defineConfig({
schema: "prisma/schema.prisma",
migrations: {
path: "prisma/migrations",
seed: "tsx prisma/seed.ts",
},
datasource: {
url: env("DATABASE_URL"),
},
});3Verify
Run the seed explicitly.
npx prisma db seedConfirmed by prisma.io
How do I stop it coming back?
- Run the seed file directly with tsx whenever the wrapper only says exit code 1.
- Disconnect the client and exit with a non-zero code in the catch handler, so failures stay visible.
- After a Prisma major upgrade, reread the seeding guide: the config location and client setup change.
- Run the seed explicitly after migrate reset; do not expect it to run by itself.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
tsconfig rejects allowImportingTsExtensions
An error that allowImportingTsExtensions needs noEmit or emitDeclarationOnly
allowImportingTsExtensions lets files import each other with .ts or .tsx extensions, and TypeScript only allows it together with noEmit or emitDeclarationOnly.
2 causes, each with a fixWeb apps
Cypress refuses to start with 'Your configFile is invalid'
Your configFile threw an error from: /path/to/cypress.config.ts
Cypress could not load cypress.config.js or .ts, or found something wrong in it.
5 causes, each with a fixWeb apps
ESLint cannot decide which copy of the @typescript-eslint plugin to use
The message lists two file paths for the same plugin, each with the name of the config that loaded it
ESLint found the same plugin at two different file paths and will not pick one.
3 causes, each with a fixWeb apps
ESLint says it cannot resolve a path to a module that does exist
Unable to resolve path to module 'react'. import/no-unresolved
import/no-unresolved fails when eslint-plugin-import cannot find the file or package on disk with its resolver.
4 causes, each with a fixWeb apps
ESLint was configured to run using parserOptions.project, but the file is not in the TSConfig
However, that TSConfig does not include this file
Type-aware linting needs every linted file to belong to a TypeScript project.
4 causes, each with a fixWeb apps
Upgrading to Next.js 16: middleware becomes proxy, and the other things that break
Missing Required default.js for Parallel Route
Next.js 16 renames middleware.ts to proxy.ts and its exported function to proxy.
6 causes, each with a fix