“npx prisma db seed”命令出现错误:命令失败,退出代码为 1:ts-node --compiler-options {“module”:“CommonJS”} prisma/seed.ts

问题描述 投票:0回答:4

这是package.json文件

当我运行“npx prisma db seeds”时,我收到此错误 运行种子命令时出错: 错误:命令失败,退出代码 1:ts-node --compiler-options {"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"
}
}
typescript next.js prisma
4个回答
2
投票

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

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

然后我在package.json文件中添加,右after

"devDependencies": {},

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

之后,我可以毫无问题地运行下面的命令(并且数据库已填充):

npx prisma db seed

命令输出:

从.env加载的环境变量 运行种子命令

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

种子命令已执行。

Prisma版本:4.9.0


1
投票

首先,通过在终端中输入

ts-node
来安装
npm install -g ts-node

然后在你的 package.json 文件中

添加这个

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

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


0
投票

遵循棱镜文档

第 3 步:

添加

typescript
ts-node
@types/node
开发依赖项:

在你的

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

npm install -D @types/node

0
投票

你尝试过这样做吗?

"prisma": {
  "seed": "npx ts-node --esm prisma/seed.ts"
}
© www.soinside.com 2019 - 2024. All rights reserved.