prisma generate throws TypeError: collection is not iterable

prisma generate throws TypeError: collection is not iterable

我正在使用带有 prisma 的打字稿,当我尝试 运行 prisma generate 时,它一直在抛出

TypeError: collection is not iterable.
 at keyBy (/node_modules/@prisma/client/generator-build/index.js:57685:21)
    at Object.getTypeMap (/node_modules/@prisma/client/generator-build/index.js:59468:17)
    at new DMMFHelper (/node_modules/@prisma/client/generator-build/index.js:59365:25)
    at new TSClient (/node_modules/@prisma/client/generator-build/index.js:60630:17)
    at buildClient (/node_modules/@prisma/client/generator-build/index.js:60876:18)
    at generateClient (/node_modules/@prisma/client/generator-build/index.js:60947:47)
    at async LineStream.<anonymous> (/node_modules/@prisma/client/generator-build/index.js:54186:24)

我认为设置有问题,但找不到具体原因。

我的prisma版本是3.9.2,@prisma/client是3.10.0,用的是macos

tsconfig.json

{
  "compilerOptions": {
    /* Language and Environment */
    "target": "es2018",

    /* Modules */
    "module": "commonjs",
    "moduleResolution": "node",

    /* Emit */
    "outDir": "./build",
    "rootDir": "./src",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true,

    /* Type Checking */
    "strict": true,
    "skipLibCheck": true
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules"]
}

package.json

{
  "scripts": {
    "dev": "nodemon --watch \"src/**/*.ts\" --exec \"ts-node\" src/app.ts",
    "build": "tsc -p tsconfig.json",
    "start": "node build/app.js",
    "prepare": "husky install",
    "lint-staged": "lint-staged"
  },
  "author": "",
  "license": "MIT",
  "lint-staged": {
    "src/**/*.{ts,tsx}": [
      "eslint --fix",
      "prettier --write"
    ]
  },
  "husky": {
    "hooks": {
      "pre-commit": "lint-staged"
    }
  },
  "prisma": {
    "schema": "src/prisma/schema.prisma"
  },
  "dependencies": {
    "@prisma/client": "^3.10.0",
    "@types/morgan": "^1.9.3",
    "aws-sdk": "^2.1077.0",
    "cors": "^2.8.5",
    "dotenv": "^16.0.0",
    "express": "^4.17.3",
    "mysql": "^2.18.1",
    "prisma": "^3.9.2"
  },
  "devDependencies": {
    "@types/cors": "^2.8.12",
    "@types/express": "^4.17.13",
    "@types/mysql": "^2.15.21",
    "@types/node": "^17.0.18",
    "@typescript-eslint/eslint-plugin": "^5.12.0",
    "@typescript-eslint/parser": "^5.12.0",
    "eslint": "^8.9.0",
    "eslint-config-prettier": "^8.4.0",
    "eslint-plugin-prettier": "^4.0.0",
    "husky": "^7.0.0",
    "lint-staged": "^12.3.4",
    "prettier": "^2.5.1",
    "ts-node": "^10.5.0",
    "typescript": "^4.5.5"
  }
}


解决了!

我刚刚在 devdependency 中重新安装了 Prisma,它工作正常。

您需要将这两个包升级到最新版本

yarn add prisma@latest / npm i prisma@latest
yarn add @prisma/client@latest / npm i @prisma/client@latest