You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

M3芯片环境下Prisma Client找不到darwin-arm64查询引擎求助

Prisma Client 在Serverless Lambda中找不到Query Engine的解决办法

问题场景

通过Prisma Introspect完成数据库表结构映射生成Schema后,使用Serverless框架部署Lambda函数,调用API时触发错误:

prisma.user.findMany() invocation: Prisma Client could not locate the Query Engine for runtime "darwin-arm64".

相关代码片段

Lambda中调用Prisma的代码:

import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()
const result1 = await prisma.user.findMany()

生成的Prisma Model

model user {
  id                         Int                          @id(map: "PK_cace4a159ff9f2512dd42373760") @default(autoincrement())
  first_name                 String?                      @db.VarChar
  user_identifier            String                       @db.VarChar
  password                   String                       @db.VarChar
  is_verified                Boolean                      @default(false)
  is_blocked                 Boolean                      @default(false)
  stripe_customer_id         String                       @default("abc") @db.VarChar
  created_at                 DateTime                     @default(now()) @db.Timestamp(6)
  profileId                  Int?                         @unique(map: "REL_9466682df91534dd95e4dbaa61")
  lottery_winner             lottery_winner[]
  payments                   payments[]
  user_profile               user_profile?                @relation(fields: [profileId], references: [id], onDelete: NoAction, onUpdate: NoAction, map: "FK_9466682df91534dd95e4dbaa616")
  user_lottery_participation user_lottery_participation[]
  user_notifications         user_notifications[]
  user_verification_code     user_verification_code[]
}

对应SQL表结构

CREATE TABLE "user" (
    "id" SERIAL NOT NULL,
    "first_name" VARCHAR,
    "user_identifier" VARCHAR NOT NULL,
    "password" VARCHAR NOT NULL,
    "is_verified" BOOLEAN NOT NULL DEFAULT false,
    "is_blocked" BOOLEAN NOT NULL DEFAULT false,
    "stripe_customer_id" VARCHAR NOT NULL DEFAULT 'abc',
    "created_at" TIMESTAMP(6) NOT NULL DEFAULT CURRENT_TIMESTAMP,
    "profileId" INTEGER,

    CONSTRAINT "PK_cace4a159ff9f2512dd42373760" PRIMARY KEY ("id")
);

Prisma版本信息

prisma                  : 5.19.0
@prisma/client          : 5.19.0
Computed binaryTarget   : darwin-arm64
Operating System        : darwin
Architecture            : arm64
Node.js                 : v18.20.2
Query Engine (Node-API) : libquery-engine 5fe21811a6ba0b952a3bc71400666511fe3b902f (at ../node_modules/@prisma/engines/libquery_engine-darwin-arm64.dylib.node)
Schema Engine           : schema-engine-cli 5fe21811a6ba0b952a3bc71400666511fe3b902f (at ../node_modules/@prisma/engines/schema-engine-darwin-arm64)
Schema Wasm             : @prisma/prisma-schema-wasm 5.19.0-31.5fe21811a6ba0b952a3bc71400666511fe3b902f
Default Engines Hash    : 5fe21811a6ba0b952a3bc71400666511fe3b902f
Studio                  : 0.502.0

Prisma Generator与数据源配置

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

解决步骤

1. 修改Prisma Generator配置,指定多平台二进制目标

Lambda运行在Linux环境,而本地开发用的是Darwin(macOS),需要让Prisma同时生成两种环境的Query Engine。修改schema.prisma中的generator部分:

generator client {
  provider      = "prisma-client-js"
  // 保留本地开发的native目标,同时添加Lambda对应的Linux架构
  binaryTargets = ["native", "linux-arm64"]
}

注意:如果你的Lambda使用x86架构,将linux-arm64替换为linux-x64。

2. 重新生成Prisma Client

执行命令重新生成包含多平台引擎的Prisma Client:

npx prisma generate

执行后,node_modules/@prisma/engines目录下会同时出现本地和Linux平台的引擎文件。

3. 确保Serverless打包包含Lambda所需的引擎文件

如果使用Serverless Webpack插件,默认可能会忽略二进制文件,需要配置Webpack复制对应的引擎文件到打包目录。示例Webpack配置:

const CopyPlugin = require('copy-webpack-plugin');

module.exports = {
  // 其他Webpack配置项
  plugins: [
    new CopyPlugin({
      patterns: [
        {
          from: './node_modules/@prisma/engines/libquery_engine-linux-arm64.so.node',
          to: './node_modules/@prisma/engines/'
        }
      ]
    })
  ]
};

如果不使用Webpack,直接通过Serverless默认打包,确保node_modules/@prisma/engines目录被完整包含在打包的zip文件中。

4. 验证打包结果

部署前检查生成的zip包,确认node_modules/@prisma/engines/libquery_engine-linux-arm64.so.node(对应架构的文件)存在,避免被打包工具遗漏。


内容的提问来源于stack exchange,提问作者Shehryar Tanoli

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 06:05:00