P
Prisma•6mo ago
vatsobuggy

Binary does not get bundled for lambdas

Upon sls deploy, all goes well. But when I try to hit an endpoint that will connect to the DB, I see: "Prisma Client could not locate the Query Engine for runtime "rhel-openssl-3.0.x".\n\nThis is likely caused by a bundler that has not copied "libquery_engine-rhel-openssl-3.0.x.so.node" next to the resulting bundle.\nEnsure that "libquery_engine-rhel-openssl-3.0.x.so.node" has been copied next to the bundle or in "prisma/generated/client" "The following locations have been searched:", " /var/task/prisma/generated/client", " /var/task/src", " /Users/utkarshvats/Documents/play/park wash/park-wash-api/prisma/generated/client", " /var/.prisma/client", " /tmp/prisma-engines", " at yl (/var/task/src/handlers/auth.js:882734:77)", " at async Object.loadLibrary (/var/task/src/handlers/auth.js:883360:31)", " at async Gr.loadEngine (/var/task/src/handlers/auth.js:883491:58)", " at async Gr.instantiateLibrary (/var/task/src/handlers/auth.js:883470:72)" Config: generator client { provider = "prisma-client-js" binaryTargets = ["native", "rhel-openssl-3.0.x"] } Bundler is esbuild. The relevant snippet from serverless.yml: plugins: - serverless-offline - serverless-esbuild - serverless-dotenv-plugin custom: stage: ${opt:stage, 'dev'} esbuild: bundle: true minify: false sourcemap: true exclude: - 'pg-native' external: - 'pg-native' platform: 'node' target: 'node20' define: 'require.resolve': undefined Tried manually copying the client in the @prisma/client, specifying 'package' in serverless.yml and specified the "output" as "prisma/generated/client" in schema.prisma: generator client { provider = "prisma-client-js" binaryTargets = ["native", "rhel-openssl-3.0.x"] } I cannot find a way around this. PLEASE HELP!
3 Replies
Prisma AI Help
Prisma AI Help•6mo ago
You opted for speed from this bot. Let's conjure up an answer right now! This error occurs because the Prisma query engine binary (libquery_engine-rhel-openssl-3.0.x.so.node) is not being bundled or copied to the correct location in your Lambda deployment. This is a common issue when using esbuild or other bundlers with serverless environments. Key points and solutions from the knowledge sources: 1. Binary Not Bundled by Default: The Prisma engine binary is not automatically included by esbuild or the Serverless Framework. You must explicitly copy it to your deployment package or ensure it is present in a Lambda Layer Query engine not found Serverless AWS Lambda. 2. Manual Copying: Many users solve this by manually copying the required binary to the output directory after bundling. For example, in a CDK/esbuild setup, you can use an afterBundling hook to copy the binary:
afterBundling(inputDir, outputDir) {
return [
`cp ${inputDir}/node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node ${outputDir}/prisma/generated/client/`
];
}

afterBundling(inputDir, outputDir) {
return [
`cp ${inputDir}/node_modules/.prisma/client/libquery_engine-rhel-openssl-3.0.x.so.node ${outputDir}/prisma/generated/client/`
];
}

Or, for Serverless Framework, use the package.patterns field to include the binary Prisma Client in AWS Lambda with TypeScript. 3. Lambda Layer Alternative: For a cleaner solution, consider creating a Lambda Layer containing the Prisma client and engine binary, then reference that layer in your Lambda function EROFS: read-only file system, chmod. 4. Check Output Path: If you set a custom output in schema.prisma, ensure your deployment and runtime paths match exactly where the binary is expected. Sometimes, removing the custom output helps, as some users have found issues with custom output paths in monorepos or serverless setups Can't find prisma binary on vercel serverless function. Summary:
You must ensure that libque ry_engine-rhel-openssl-3.0.x.so.node is present in one of the searched locations at runtime. The most reliable way is to copy it manually during your build/deploy process or use a Lambda Layer. This is a packaging/bundling issue, not a Prisma bug. 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
Nurul
Nurul•6mo ago
Did the bot response help in resolving this issue or are you still running into this?
vatsobuggy
vatsobuggyOP•6mo ago
Still running into this I don’t think there is a reference I can use to create a lambda layer for prisma

Did you find this page helpful?