0

I'm building a backend using Prisma, Postgres 14.5, Node 18, and Typescript. Every time try to seed the DB I get the following:

└ ➜ yarn prisma db seed
Environment variables loaded from .env
Running seed command `ts-node prisma/seed.ts` ...

An error occurred while running the seed command:
Error: Command failed with ENOENT: ts-node prisma/seed.ts
spawn ts-node ENOENT

ENOENT errors mean "No such file or directory"

I have this in my package.json:

  "prisma": {
    "seed": "ts-node prisma/seed.ts"
  },

My seed file is located at prisma/seed.ts and contains:

import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

async function main() {
  const person = await prisma.name.upsert({
    where: { id: 0 },
    update: {},
    create: {
      firstName: 'Sakiko',
    },
  });
}

main()
  .then(async () => {
    await prisma.$disconnect();
  })
  .catch(async (e) => {
    console.error(e);
    await prisma.$disconnect();
    process.exit(1);
  });

Ann Kilzer
  • 1,266
  • 3
  • 16
  • 39
  • Can you try updating the file path like this. `./prisma/seed.ts` – MC Naveen Dec 28 '22 at 03:09
  • @MCNaveen Good thought but I tried that and still got the same error – Ann Kilzer Dec 28 '22 at 04:05
  • 1
    I'm not using ts. When I don't have that file I get a different error. This may be helpful https://stackoverflow.com/questions/27688804/how-do-i-debug-error-spawn-enoent-on-node-js. – shmuels Dec 28 '22 at 16:57
  • @shmuels Thanks, I was so focused on the seed file I didn't realize ENOENT was complaining about the missing command – Ann Kilzer Dec 29 '22 at 02:52

1 Answers1

0

Turns out I was missing ts-node as we don't have our build fully set up yet. So I fixed it with yarn add ts-node.

Additionally, I had to simplify our tsconfig.json to remove the compilerOptions.rootDir as the prisma code is outside the src directory.

Ann Kilzer
  • 1,266
  • 3
  • 16
  • 39