My small Next.js project has been failing to build on Vercel if I try to update the sharp dependency to anything beyond 0.32.6. All 0.33.x versions cause the build to fail. The build logs show only the following:
▲ Next.js 14.2.5
Creating an optimized production build ...
free(): invalid size
Error: Command "npm run build" exited with SIGABRT
Does anyone know what is happening here or how to even troubleshoot? Everything builds fine locally, of course.
The Vercel build team and lovell worked together to fix it. Please give the recommended solution a try and let me know whether or not that works for you.
@amyegan I did go down that path while attempting to troubleshoot on my own, but I don’t understand the proposed solution. They are talking about @vercel/nft and it looks like there was a patch merged into it to address this issue, but what am I supposed to do with that? I don’t have @vercel/nft in my dependencies (nowhere in node_modules). It was my understanding Vercel uses that package as part of its build toolchain or something. I did try adding it as a dependency, but that didn’t fix anything so I removed it again. What can I do in my project to ensure it’s “being used” (if that is the solution)?
It may be a dependency of a dependency. You can try updating the lockfile by deleting the existing package-lock.json, deleting node_modules, and running npm install again.
This is just pinning sharp to an old version, which is what I’ve been doing. But it sure would be nice to be able to update and get on the latest version.
That solution is specifically for pnpm users (I’m using npm), and corepack is going away so I’d be hesitant to rely on this approach even if it were applicable.
While creating this reproduction, I noticed it’s definitely related to how I’m rendering the image with the Image component from next/image. If I remove this particular instance of the Image component in my real project (while leaving other Image uses in place), it fixes the build issue.
The free(): invalid size from the failed build logs makes me think it’s running out of memory or something.
Edit: Keep in mind, this builds fine locally - just not on Vercel.
In an effort to pare down the reproduction even further, I discovered the combination of @plaiceholder/next and sharp 0.33.x is the problem. That combo is what fails to build on Vercel.