これは、CI上でPrismaでシードスクリプトを実行した時のエラーに関する忘備録。
Cypressを使ったE2Eのテストを行う際にPrismaのシードスクリプトを実行したところ次のエラーが発生した。
...
Running seed command `ts-node --require tsconfig-paths/register prisma/seed.ts` ...
PrismaClientInitializationError:
Invalid `prisma.user.delete()` invocation in
/home/runner/work/example-app/example-app/prisma/seed.ts:22:27
19 const email = "rachel@remix.run";
20
21 // cleanup the existing database
→ 22 await prisma.user.delete(
Query engine library for current platform "debian-openssl-3.0.x" could not be found.
You incorrectly pinned it to debian-openssl-3.0.x
This probably happens, because you built Prisma Client on a different platform.
(Prisma Client looked in "/home/runner/work/example-app/example-app/node_modules/@prisma/client/runtime/libquery_engine-debian-openssl-3.0.x.so.node")
Searched Locations:
/home/runner/work/example-app/example-app/node_modules/.prisma/client
/home/runner/work/example-app/example-app/node_modules/@prisma/client
/home/runner/work/example-app/example-app/node_modules/@prisma/client
/home/runner/work/example-app/example-app/node_modules/.prisma/client
/home/runner/work/example-app/example-app/prisma
/tmp/prisma-engines
/home/runner/work/example-app/example-app/node_modules/.prisma/client
To solve this problem, add the platform "debian-openssl-3.0.x" to the "binaryTargets" attribute in the "generator" block in the "schema.prisma" file:
generator client {
provider = "prisma-client-js"
binaryTargets = ["native"]
}
Then run "prisma generate" for your changes to take effect.
Read more about deploying Prisma Client: https://pris.ly/d/client-generator
at RequestHandler.handleRequestError (/home/runner/work/example-app/example-app/node_modules/@prisma/client/runtime/index.js:34316:13)
at /home/runner/work/example-app/example-app/node_modules/@prisma/client/runtime/index.js:34737:25
at async PrismaClient._executeRequest (/home/runner/work/example-app/example-app/node_modules/@prisma/client/runtime/index.js:35301:22)
at async PrismaClient._request (/home/runner/work/example-app/example-app/node_modules/@prisma/client/runtime/index.js:35273:16)
at async seed (/home/runner/work/example-app/example-app/prisma/seed.ts:22:3) {
clientVersion: '4.6.1',
errorCode: undefined
}
An error occurred while running the seed command:
Error: Command failed with exit code 1: ts-node --require tsconfig-paths/register prisma/seed.ts
この時のPrismaのバージョンは次のとおり。
"dependencies": {
"@prisma/client": "^4.5.0"
},
"devDependencies": {
"prisma": "^4.10.1"
}
エラーログの指摘通り、schema.prismaを修正して、binaryTargets
にdebian-openssl-3.0.x
を追加するという方法も考えた。
しかし、すでにある程度動いているアプリケーションであったため、あまりschema.prismaを修正するのは避けたいと考えた。
そこで、Prismaのバージョンを上げてみることにした。
$ npm install prisma@latest @prisma/client@latest
すると、次のようにバージョンが上がった。
"dependencies": {
"@prisma/client": "^4.11.0"
},
"devDependencies": {
"prisma": "^4.11.0"
}
この状態でコミットを行い、CIを実行したところ、エラーが解消された。