【问题标题】:"npx prisma db seed" command got Error: Command failed with exit code 1: ts-node --compiler-options {"module":"CommonJS"} prisma/seed.ts\"npx prisma db seed\" 命令出错:命令失败,退出代码 1:ts-node --compiler-options {\"module\":\"CommonJS\"} prisma/seed.ts
【发布时间】:2023-01-29 04:18:29
【问题描述】:

这是 package.json 文件

当我运行“npx prisma db seed”时出现此错误 运行 seed 命令时出现错误: 错误:命令失败,退出代码 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


    【解决方案1】:

    跟随棱镜docs

    在第 3 步中:

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

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

    npm install -D @types/node
    

    【讨论】:

    • 我做到了,但仍然无法正常工作......它有同样的错误
    • @nattyeth 您应该将prisma 更新到最新版本,我在使用旧版本时也遇到过这个问题。
    【解决方案2】:

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

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

    然后我加入包.json文件,对"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 ...

    种子命令已执行。

    棱镜版本:4.9.0

    【讨论】:

      猜你喜欢
      • 2022-10-08
      • 2018-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-12
      • 2015-10-12
      • 2022-06-17
      • 2019-12-04
      相关资源
      最近更新 更多