@prisma/engines weights 113 MB and causes maximum size limit error on Vercel
Problem
Bug description When I try to deploy a Next.js + GraphQL + Prisma application on Vercel I receive an error about exceeding the lambda function limit. [code block] Full log here: https://gist.github.com/talentlessguy/74f58664cd5af05407037be15b3b25a1 How to reproduce 1. Create a new Next.js project with these files: https://gist.github.com/talentlessguy/9cac915be4fa6a1ea911c7f0ead5fa2b Expected behavior I expected a Next.js app to build and launch as it usually does (it did run fine 1-2 weeks ago) Prisma information Schema: https://gist.github.com/talentlessguy/9cac915be4fa6a1ea911c7f0ead5fa2b#file-graphql_schema-ts Environment & setup - OS: Vercel Linux runtime - Database: PostgreSQL - Node.js version: 14.16 - Prisma version: 2.22.0 [code block]
Error Output
error about exceeding the lambda function limit.
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Reduce Prisma Engine Size for Vercel Deployment
The Prisma engine binaries are large (113 MB), which exceeds the maximum size limit for Vercel's serverless functions. This issue arises because Vercel has strict limits on the total size of the deployment package, and the inclusion of large binaries can lead to deployment failures.
Awaiting Verification
Be the first to verify this fix
- 1
Update Prisma to the Latest Version
Upgrade Prisma to the latest version to benefit from optimizations and potentially smaller binary sizes. This can help reduce the overall size of the deployment package.
bashnpm install @prisma/client@latest prisma@latest - 2
Use Prisma Client with Only Required Engines
Configure Prisma to only include the necessary engines for your database. This can be done by setting the `binaryTargets` in your `schema.prisma` file to only include the target you need (e.g., `native` for local development and `debian-openssl-1.1.x` for Vercel).
prismagenerator client { provider = "prisma-client-js" binaryTargets = ["native", "debian-openssl-1.1.x"] } - 3
Optimize Build Output
Modify your build settings to exclude unnecessary files from the deployment. This can be done by adding a `.vercelignore` file to your project root to ignore files that are not needed in production.
plaintextnode_modules/ prisma/migrations/ *.log - 4
Use Environment Variables for Database Connection
Ensure that your database connection string is set as an environment variable in Vercel instead of being hardcoded in your application. This can help reduce the size of the deployment package.
plaintextDATABASE_URL='your_database_connection_string' - 5
Test Deployment
After making the above changes, attempt to redeploy your application on Vercel. Monitor the deployment logs for any errors related to size limits.
bashvercel --prod
Validation
Confirm the fix by successfully deploying the application on Vercel without encountering the 'exceeding the lambda function limit' error. Additionally, verify that the application functions correctly in production.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep