Issue with Sharp Module on Netlify

I am experiencing an issue with the Sharp module while deploying my application on Netlify. I am using Node.js version 20.11.0, and my netlify.toml file is configured as follows:

[build]
command = "npm run build"
publish = ".next"
environment = { NODE_VERSION = "20.11.0" }

[dev]
command = "npm run dev"
port = 8888

[functions]
external_node_modules = ["sharp"]
included_files = ["node_modules/sharp/**/*"]

The build process completes successfully, and the website works fine. However, I encounter a 500 error when making a POST request to the endpoint /api/retrieval/retrieve. This endpoint works correctly on my local environment and on Vercel, but I am facing this issue only on Netlify.

Here are the relevant logs from Netlify:

I have attempted the following steps to resolve the issue:

  1. Installed the latest version of Sharp, but I received errors during the build process.
  2. Run the command npm install --ignore-scripts=false --foreground-scripts --verbose sharp to get more information.
  3. Executed npm install --platform=linux --arch=x64 sharp to ensure compatibility with the Netlify environment.

Unfortunately, none of these steps have resolved the issue.

Could anyone provide guidance on how to solve this problem?

Same issue here:

Are you doing anything with sharp in your server-side functionality?

did u find solution?

Had the same issue.
Gave this command to Claude Code/Cursor/etc. to fix it:

Please switch from using "sharp" for image processing to this one that uses WASM so that the backend can be deployed to Netlify functions. 

https://www.npmjs.com/package/@img/sharp-wasm32

You might get an error when you deploy, you can copy that error and paste it to the AI again and it’ll fix it and image processing should work fine after that.

All the best.