kira-0521 / todo-app-ai

https://todo-app-ai-bay.vercel.app
1 stars 0 forks source link

✅ seedingできない #28

Closed kira-0521 closed 8 months ago

kira-0521 commented 8 months ago

https://www.prisma.io/docs/orm/prisma-migrate/workflows/seeding

Nextjsを使用する場合下記の設定

package.json

"prisma": {
    "seed": "ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts"
  }

shell

❯ npx prisma db seed
Environment variables loaded from .env
Running seed command `ts-node --compiler-options {"module":"CommonJS"} prisma/seed.ts` ...
TypeError: Unknown file extension ".ts" for /Users/tanaka/workdir/gizumo/grit/todo-app-ai/prisma/seed.ts
    at Object.getFileProtocolModuleFormat [as file:] (node:internal/modules/esm/get_format:160:9)
    at defaultGetFormat (node:internal/modules/esm/get_format:203:36)
    at defaultLoad (node:internal/modules/esm/load:143:22)
    at async ModuleLoader.load (node:internal/modules/esm/loader:409:7)
    at async ModuleLoader.moduleProvider (node:internal/modules/esm/loader:291:45)
    at async link (node:internal/modules/esm/module_job:76:21) {
  code: 'ERR_UNKNOWN_FILE_EXTENSION'
}

An error occurred while running the seed command:
Error: Command failed with exit code 1: ts-node --compiler-options {"module":"CommonJS"} prisma/seed.ts
kira-0521 commented 8 months ago

https://github.com/prisma/prisma/discussions/20369

-> TypeScript-nodeがデフォルトでcommonJSを実行するため、.tsが認識できていない

そもそもBunはTypeScript をビルトインサポートなのでいかにすればOK🙆

"prisma": {
    "seed": "bun prisma/seed.ts"
  }
kira-0521 commented 8 months ago

bunでseedingできないが、エラーは吐かれない

https://github.com/prisma/prisma/issues/21324#issuecomment-1751945478

上記issueよりトップレベルawaitを使えば解決するという記述

---> ✅ いけた