[英]How can I fix an error with the seed file in Prisma and typescript?
我正在使用 Prisma、Postgres 14.5、Node 18 和 Typescript 構建后端。每次嘗試為數據庫播種時,我都會得到以下信息:
└ ➜ 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 錯誤表示“沒有這樣的文件或目錄”
我的package.json
中有這個:
"prisma": {
"seed": "ts-node prisma/seed.ts"
},
我的種子文件位於prisma/seed.ts
並包含:
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);
});
原來我缺少ts-node
,因為我們還沒有完全設置我們的構建。 所以我用yarn add ts-node
修復了它。
此外,我必須簡化我們的tsconfig.json
以刪除compilerOptions.rootDir
,因為 prisma 代碼位於src
目錄之外。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.