"npx prisma db seed"命令出错:命令失败,退出代码为 1:ts-node --compiler-options { "module" : "CommonJS" } prisma/s



这是package.json文件

当我跑步时;npx棱镜db种子";我犯了这个错误运行种子命令时出错:错误:命令失败,退出代码为1:ts node--编译器选项{"module":"CommonJS"}prisma/seed.ts

{
"name": "myapp",
"private": true,
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"lint": "next lint"
},
"dependencies": {
"@chakra-ui/layout": "^1.5.1",
"@chakra-ui/react": "^1.7.2",
"@dh-react-hooks/use-raf": "^0.9.1",
"@emotion/react": "^11.6.0",
"@emotion/styled": "^11.6.0",
"@prisma/client": "^3.6.0",
"bcrypt": "^5.0.1",
"cookie": "^0.4.1",
"cookies": "^0.8.0",
"easy-peasy": "^5.0.4",
"format-duration": "^1.4.0",
"framer-motion": "^4.1.17",
"jsonwebtoken": "^8.5.1",
"next": "12.0.7",
"react": "17.0.2",
"react-dom": "17.0.2",
"react-howler": "^5.2.0",
"react-icons": "^4.3.1",
"reset-css": "^5.0.1",
"swr": "^1.1.1"
},
"devDependencies": {
"@types/react": "^17.0.37",
"@typescript-eslint/eslint-plugin": "^5.6.0",
"@typescript-eslint/parser": "^5.6.0",
"babel-plugin-superjson-next": "^0.4.2",
"eslint": "^8.4.1",
"eslint-config-airbnb": "^19.0.2",
"eslint-config-next": "12.0.7",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsx-a11y": "^6.5.1",
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-react": "^7.27.1",
"eslint-plugin-react-hooks": "^4.3.0",
"prettier": "^2.4.1",
"prisma": "^3.6.0",
"ts-node": "^10.4.0",
"typescript": "^4.8.4"
},
"prisma": {
"seed": "ts-node --compiler-options {"module":"CommonJS"} prisma/seed.ts"
}
}

使用Next.js我已经通过运行以下命令解决了这个问题:

npm install -D typescript ts-node @types/node

然后我在package.json文件中添加,在"devDependencies": {},:之后

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

在那之后,我能够毫无问题地运行下面的命令(并且DB已经填充(:

npx prisma db seed

命令输出:

从.env加载的环境变量正在运行种子命令ts-node --compiler-options {"module":"CommonJS"} prisma/seed.ts。。。

种子命令已执行。

Prisma版本:4.9.0

首先,通过在终端中键入npm install -g ts-node来安装ts-node

然后在你的package.json文件中

添加这个

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

取自:[https://www.prisma.io/docs/guides/database/seed-database]

遵循prisma文档

第3步:

添加typescriptts-node@types/node开发依赖项:

在您的package.json中,devDependencies中没有@types/node,所以我认为您必须安装它,然后再次尝试播种

npm install -D @types/node

最新更新