Fixing Sharp libvips Errors on Vercel

Resumo

Pixel’s announcement explains how sharp 0.34 can fail on Vercel when Next.js omits the separate libvips package from serverless functions. It shares a route-specific outputFileTracingIncludes fix and warns that importing constants from a module that imports sharp can pull in the native dependency unexpectedly.

DEV Community

sharp on Vercel: "libvips-cpp.so: cannot open shared object file" when the install was clean

Our first production deploy of Brifora (an AI design studio built with Next.js and Supabase) looked perfect — until every route that used sharp started returning 500. The symptom. The function crashed while loading the module, before the first line of the handler ran. The Vercel runtime log said: Error: Could not load the "sharp" module using the linux-x64 runtime
ERR_DLOPEN_FAILED: libvips-cpp.so.8.18.3: cannot open shared object file:
No such file or directory
The build log was clean: all packages installed, no optional dependency skipped, and the lock file had both Linux entries with the right os and cpu. Read which file is missing. Not sharp, not its native binding — libvips-cpp.so. That detail is the whole story. The cause. Since sharp 0.34, libvips ships in a separate package, @img/sharp-libvips-. The binding loads it through an rpath at dlopen time. Nothing ever requires it, so Next's output file tracing doesn't see it and doesn't copy it into the serverless function. (serverExternalPackages is not the problem — sharp is already external, as the error itself shows.) The fix. Tell the tracer explicitly, in next.config.ts: outputFileTracingIncludes: {
'/api/generate': ['node_modules/@img/'],
'/api/uploads': ['node_modules/@img/
'],
'/api/vectorize': ['node_modules/@img/'],
'/api/edit': ['node_modules/@img/
'],
'/api/maintenance/sweep-uploads': ['node_modules/@img/'],
},
We listed routes by name instead of '/
': libvips weighs tens of megabytes, and the login page or the gallery has no use for it. Act two, two days later. The same error came back — this time on two pages, not API routes. They don't process images at all. But they imported a couple of constants (UPLOAD_MAX_BYTES, UPLOAD_TYPES) from our uploads module — and that module imports sharp. A constant pulled the whole native dependency in with it. We had a comment in the config saying "don't forget to add new routes here". It didn't help: the person who wrote the comment was the person who forgot. So we replaced the comment with a check — a command whose output must have as many lines as there are @img entries in the config: grep -rln "generation/uploads'|generation/preview'|generation/svg'|generation/sources'" src/app/
Takeaways: A clean install log doesn't mean a native library reaches your serverless function. The tracer follows require, not rpath or dlopen. Read exactly which file is missing: libvips-cpp.so and sharp.node point to different problems. A hand-maintained list of exceptions will go stale. Replace "remember to update this" comments with a command that checks it. Importing a constant from a module imports its heavy dependencies too. Keep constants in a light file. Brifora: https://brifora.app — built by Weblevo (weblevo.com)
Fixing Sharp libvips Errors on Vercel
Powered by Readybot.io*

As últimas novidades de Pixel

Fix GitHub Pages: Missing Artifact Error

Pixel's announcement explains why the GitHub Pages deploy action reports that no github-pages artifact was found. It covers skipped or failed build jobs, missing uploads, …

Rotate DB and Redis Passwords Without Downtime

Pixel shares a practical guide to rotating exposed database and Redis passwords without interrupting application connections. The approach updates Secrets, changes service credentials, and gradually …

AI Agent Receipts Prove What Actually Executed

Pixel’s announcement examines how public Zambo receipts verify what an AI agent actually did. A BTC price fetch succeeded with a recomputable output hash, while …