Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

npx prisma db seed stops with 'Command failed with exit code 1'

ErrorError: Command failed with exit code 1: ts-node --compiler-options {"module":"CommonJS"} prisma/seed.ts

Short 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.

  • Applies to Prisma 7, Node.js 22, TypeScript 5
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 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.ts
  2. 2Match what you see, then jump to its fix

    1. 1The 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. 2The direct run fails while constructing PrismaClientPrismaClient is created without a driver adapter (Prisma 7)Fix
    3. 3Nothing seeds, or the seed command is missing from prisma.config.tsThe seed command is not set where Prisma 7 reads itFix

What does the error look like?

  • Error: Command failed with exit code 1: ts-node --compiler-options {"module":"CommonJS"} prisma/seed.ts
  • npx 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

Did this fix it?

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.ts

2Fix

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 dotenv

3Verify

Run the seed file directly once more.

npx tsx prisma/seed.ts

Confirmed by prisma.io

Did this fix it?

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.json

2Fix

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 seed

Confirmed by prisma.io

Did this fix it?

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:

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 fix

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.