无法找到当前平台“debian-openssl-1.1.x”的 Prisma 查询引擎库

moh*_*sen 8 postgresql openssl node.js docker prisma

我有一个由多个微服务组成的 NodeJS/NestJS 项目。我已经在 aws kubernetes 集群上部署了 postgres 数据库以及与数据库交互的微服务 pod。我使用 Prisma 作为 ORM,当我执行到 pod 并运行时

\n
\n

npx prisma 生成

\n
\n

输出如下:

\n
Environment variables loaded from .env\nPrisma schema loaded from prisma/schema.prisma\n\n\xe2\x9c\x94 Generated Prisma Client (4.6.1 | library) to ./node_modules/@prisma/client in 1.32s\nYou can now start using Prisma Client in your code. Reference: https://pris.ly/d/client\n\nimport { PrismaClient } from '@prisma/client'\nconst prisma = new PrismaClient()\n
Run Code Online (Sandbox Code Playgroud)\n

但是当我调用 API 通过 prisma ORM 在 postgres 数据库中创建对象时,我在微服务 pod 中收到以下错误:

\n
\nerror:  PrismaClientInitializationError:\nInvalid `prisma.session.create()` invocation:\n\n\nQuery engine library for current platform "debian-openssl-1.1.x" could not be found.\nYou incorrectly pinned it to debian-openssl-1.1.x\n\nThis probably happens, because you built Prisma Client on a different platform.\n(Prisma Client looked in "/usr/src/app/node_modules/@prisma/client/runtime/libquery_engine-debian-openssl-1.1.x.so.node")\n\nSearched Locations:\n\n  /usr/src/app/node_modules/.prisma/client\n  C:\\Users\\MOHSEN\\Desktop\\cc-g\\cc-gateway\\cc-gateway\\db-manager\\node_modules\\@prisma\\client\n  /usr/src/app/node_modules/@prisma/client\n  /usr/src/app/node_modules/.prisma/client\n  /usr/src/app/node_modules/.prisma/client\n  /tmp/prisma-engines\n  /usr/src/app/node_modules/.prisma/client\n\n\nTo solve this problem, add the platform "debian-openssl-1.1.x" to the "binaryTargets" attribute in the "generator" block in the "schema.prisma" file:\ngenerator client {\n  provider      = "prisma-client-js"\n  binaryTargets = ["native"]\n}\n\nThen run "prisma generate" for your changes to take effect.\nRead more about deploying Prisma Client: https://pris.ly/d/client-generator\n    at RequestHandler.handleRequestError (/usr/src/app/node_modules/@prisma/client/runtime/index.js:34316:13)\n    at /usr/src/app/node_modules/@prisma/client/runtime/index.js:34737:25\n    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\n    at async PrismaService._executeRequest (/usr/src/app/node_modules/@prisma/client/runtime/index.js:35301:22)\n    at async PrismaService._request (/usr/src/app/node_modules/@prisma/client/runtime/index.js:35273:16)\n    at async AppService.createSession (/usr/src/app/dist/app.service.js:28:28) {\n  clientVersion: '4.6.1',\n  errorCode: undefined\n}\n
Run Code Online (Sandbox Code Playgroud)\n

这也是schema.prisma文件中的生成器客户端

\n
generator client {\n  provider = "prisma-client-js"\n  binaryTargets = ["native", "linux-musl", "debian-openssl-1.1.x"]\n} \n
Run Code Online (Sandbox Code Playgroud)\n

在此之前我遇到了同样的问题,但错误提到了“linux-musl”,如下所示:

\n
Query engine library for current platform "linux-musl" could not be found.\n
Run Code Online (Sandbox Code Playgroud)\n

尽管我在生成器块的二进制目标中使用 linux-musl 。

\n

但经过大量研究后,我发现我不应该在 docker 文件中使用alpine节点,而是使用buster,我的 docker 文件如下:

\n
FROM node:buster As development\n\nWORKDIR /usr/src/app\n\nCOPY package*.json ./\n\nRUN npm install\n\nCOPY . .\n\nRUN npm run build db-manager\n\nFROM node:buster as production\n\nWORKDIR /usr/src/app\n\nCOPY package*.json ./\n\nRUN npm install \n\nCOPY . .\n\nCOPY --from=development /usr/src/app/dist ./dist\n\nCMD ["node", "dist/main"]\n
Run Code Online (Sandbox Code Playgroud)\n

我认为问题在于,无法找到 prisma 查询引擎,因为它正在搜索特定于平台的查询引擎的错误位置。因此,我尝试提供查询引擎文件在我的 pod 中的位置,作为部署文件中的ENV变量,如下所示:

\n
apiVersion: apps/v1\nkind: Deployment\nmetadata:\n  name: db-manager\nspec:\n  replicas: 3\n  selector:\n    matchLabels:\n      app: db-manager\n  template:\n    metadata:\n      labels:\n        app: db-manager\n    spec:\n      containers:\n        - name: db-manager\n          image: image-name\n          ports:\n            - containerPort: 3002\n          env:\n            - name: PORT\n              value: "3002"\n            - name: DATABASE_URL\n              value: db url\n            - name: KAFKA_HOST\n              value: kafka url            \n            - name: PRISMA_MIGRATION_ENGINE_BINARY\n              value: /usr/src/app/node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x\n            - name: PRISMA_INTROSPECTION_ENGINE_BINARY\n              value: /usr/src/app/node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x\n            - name: PRISMA_QUERY_ENGINE_BINARY\n              value: /usr/src/app/node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node\n            - name: PRISMA_FMT_BINARY\n              value: /usr/src/app/node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x\n
Run Code Online (Sandbox Code Playgroud)\n

但它不起作用,当 prisma 尝试执行创建查询时,错误仍然发生。如果有人能帮助我,我将不胜感激。我是否做错了什么,或者这是在 aws 部署中使用时 prisma 中的错误?

\n

感谢您对此的任何评论或指导。

\n

小智 7

尝试更新到4.8.0 Prisma版本,并将schema.prisma文件中的binaryTargets属性设置为:

(...)

binaryTargets = [
  "native",
  "debian-openssl-1.1.x",
  "debian-openssl-3.0.x",
  "linux-musl",
  "linux-musl-openssl-3.0.x"
]

(...)
Run Code Online (Sandbox Code Playgroud)

别忘了奔跑yarn prisma generate

  • 为什么您建议一次启用所有二进制目标? (3认同)