Project build fails with any version of sharp after 0.32.6 (0.33.x)

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.

Thanks.

The error may be related to this issue: Vercel only: 0.33.0: error Could not load the "sharp" module using the linux-x64 runtime · Issue #3870 · lovell/sharp · GitHub

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)?

Thanks.

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.

Here are some things that worked for others:

It may be a dependency of a dependency.

It’s not, I checked.

You can try updating the lockfile by deleting the existing package-lock.json, deleting node_modules, and running npm install again.

Tried this, no change.

modify next.config.js

Tried this, no change.

include overrides

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.

enable corepack

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.

What else can we try?

I have not been able to replicate the error with any of the test projects I tried. Do you have a public minimal reproducible example repo?

Sure, check out GitHub - wKovacs64/vercel-sharp-repro

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. :thinking:

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.

Bummer, but at least the mystery is solved. :confused:

1 Like

Thanks for coming back to share what you found

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.