Deploy of next.js project to Vercel fails because of sharp

When building a new version for my next.js project, the local build goes on without any issues, but on preview deploy to vercel I get the following error:
Error: Could not load the “sharp” module using the linux-x64 runtime

I have tried everything the vercel chatbot suggested and used all my available resoiurces, tried with cursor AI, nothing works. As I said local build has no errors or warnings.

Here are the full logs:
[22:30:44.560] Running build in Washington, D.C., USA (East) – iad1
[22:30:44.678] Cloning GitHub - liornz/vic-website (Branch: next_15, Commit: 914576e)
[22:30:45.418] Previous build caches not available
[22:30:46.872] Cloning completed: 2.193s
[22:30:47.251] Running “vercel build”
[22:30:47.666] Vercel CLI 39.1.1
[22:30:48.463] Installing dependencies…
[22:30:54.715] npm warn deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: Array.prototype.sort() - JavaScript | MDN
[22:30:54.769] npm warn deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead
[22:30:54.897] npm warn deprecated rollup-plugin-terser@7.0.2: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-terser
[22:30:55.563] npm warn deprecated workbox-cacheable-response@6.6.0: workbox-background-sync@6.6.0
[22:31:19.756]
[22:31:19.757] added 878 packages in 30s
[22:31:19.758]
[22:31:19.758] 234 packages are looking for funding
[22:31:19.758] run npm fund for details
[22:31:19.787] Detected Next.js version: 15.0.3
[22:31:19.796] Running “npm run build”
[22:31:19.938]
[22:31:19.938] > vic-website@0.1.0 build
[22:31:19.938] > next build
[22:31:19.938]
[22:31:21.682] Attention: Next.js now collects completely anonymous telemetry regarding usage.
[22:31:21.682] This information is used to shape Next.js’ roadmap and prioritize features.
[22:31:21.682] You can learn more, including how to opt-out if you’d not like to participate in this anonymous program, by visiting the following URL:
[22:31:21.683] Telemetry | Next.js by Vercel - The React Framework
[22:31:21.683]
[22:31:21.737] ▲ Next.js 15.0.3
[22:31:21.738]
[22:31:21.824] Creating an optimized production build …
[22:31:22.289] > [PWA] Compile server
[22:31:22.291] > [PWA] Compile server
[22:31:22.292] > [PWA] Compile client (static)
[22:31:22.292] > [PWA] Auto register service worker with: /vercel/path0/node_modules/next-pwa/register.js
[22:31:22.293] > [PWA] Service worker: /vercel/path0/public/sw.js
[22:31:22.293] > [PWA] url: /sw.js
[22:31:22.293] > [PWA] scope: /
[22:31:42.732] Failed to compile.
[22:31:42.733]
[22:31:42.733] ./public/images/logo/logo.png
[22:31:42.733] Error: Could not load the “sharp” module using the linux-x64 runtime
[22:31:42.733] Possible solutions:
[22:31:42.734] - Ensure optional dependencies can be installed:
[22:31:42.734] npm install --include=optional sharp
[22:31:42.734] - Ensure your package manager supports multi-platform installation:
[22:31:42.734] See sharp - High performance Node.js image processing
[22:31:42.734] - Add platform-specific dependencies:
[22:31:42.735] npm install --os=linux --cpu=x64 sharp
[22:31:42.735] - Consult the installation documentation:
[22:31:42.735] See sharp - High performance Node.js image processing
[22:31:42.735] at Object. (/vercel/path0/node_modules/next/node_modules/sharp/lib/sharp.js:113:9)
[22:31:42.735] at Module._compile (node:internal/modules/cjs/loader:1364:14)
[22:31:42.735] at Module._extensions…js (node:internal/modules/cjs/loader:1422:10)
[22:31:42.736] at Module.load (node:internal/modules/cjs/loader:1203:32)
[22:31:42.736] at Module._load (node:internal/modules/cjs/loader:1019:12)
[22:31:42.736] at Module.require (node:internal/modules/cjs/loader:1231:19)
[22:31:42.736] at mod.require (/vercel/path0/node_modules/next/dist/server/require-hook.js:65:28)
[22:31:42.736] at require (node:internal/modules/helpers:177:18)
[22:31:42.737] at Object. (/vercel/path0/node_modules/next/node_modules/sharp/lib/constructor.js:10:1)
[22:31:42.737] at Module._compile (node:internal/modules/cjs/loader:1364:14)
[22:31:42.737]
[22:31:42.737] Import trace for requested module:
[22:31:42.737] ./public/images/logo/logo.png
[22:31:42.737] ./src/components/layout/logo.tsx
[22:31:42.738] ./src/components/layout/sideDrawerClient.tsx
[22:31:42.738]
[22:31:42.738] ./public/images/logo/sin-fronteras.png
[22:31:42.738] Error: Could not load the “sharp” module using the linux-x64 runtime
[22:31:42.738] Possible solutions:
[22:31:42.739] - Ensure optional dependencies can be installed:
[22:31:42.739] npm install --include=optional sharp
[22:31:42.739] - Ensure your package manager supports multi-platform installation:
[22:31:42.739] See sharp - High performance Node.js image processing
[22:31:42.739] - Add platform-specific dependencies:
[22:31:42.739] npm install --os=linux --cpu=x64 sharp
[22:31:42.739] - Consult the installation documentation:
[22:31:42.740] See sharp - High performance Node.js image processing
[22:31:42.740] at Object. (/vercel/path0/node_modules/next/node_modules/sharp/lib/sharp.js:113:9)
[22:31:42.740] at Module._compile (node:internal/modules/cjs/loader:1364:14)
[22:31:42.740] at Module._extensions…js (node:internal/modules/cjs/loader:1422:10)
[22:31:42.740] at Module.load (node:internal/modules/cjs/loader:1203:32)
[22:31:42.740] at Module._load (node:internal/modules/cjs/loader:1019:12)
[22:31:42.740] at Module.require (node:internal/modules/cjs/loader:1231:19)
[22:31:42.741] at mod.require (/vercel/path0/node_modules/next/dist/server/require-hook.js:65:28)
[22:31:42.741] at require (node:internal/modules/helpers:177:18)
[22:31:42.741] at Object. (/vercel/path0/node_modules/next/node_modules/sharp/lib/constructor.js:10:1)
[22:31:42.741] at Module._compile (node:internal/modules/cjs/loader:1364:14)
[22:31:42.741]
[22:31:42.742] Import trace for requested module:
[22:31:42.742] ./public/images/logo/sin-fronteras.png
[22:31:42.742] ./src/components/footer/social-media.tsx
[22:31:42.742] ./src/components/footer/footer.tsx
[22:31:42.742] ./src/app/[lng]/layout.tsx
[22:31:42.742]
[22:31:42.742] ./public/images/logo/sin-fronteras.png
[22:31:42.742] Error: Could not load the “sharp” module using the linux-x64 runtime
[22:31:42.743] Possible solutions:
[22:31:42.743] - Ensure optional dependencies can be installed:
[22:31:42.743] npm install --include=optional sharp
[22:31:42.743] - Ensure your package manager supports multi-platform installation:
[22:31:42.743] See sharp - High performance Node.js image processing
[22:31:42.743] - Add platform-specific dependencies:
[22:31:42.743] npm install --os=linux --cpu=x64 sharp
[22:31:42.743] - Consult the installation documentation:
[22:31:42.743] See sharp - High performance Node.js image processing
[22:31:42.743] at Object. (/vercel/path0/node_modules/next/node_modules/sharp/lib/sharp.js:113:9)
[22:31:42.743] at Module._compile (node:internal/modules/cjs/loader:1364:14)
[22:31:42.743] at Module._extensions…js (node:internal/modules/cjs/loader:1422:10)
[22:31:42.744] at Module.load (node:internal/modules/cjs/loader:1203:32)
[22:31:42.744] at Module._load (node:internal/modules/cjs/loader:1019:12)
[22:31:42.744] at Module.require (node:internal/modules/cjs/loader:1231:19)
[22:31:42.744] at mod.require (/vercel/path0/node_modules/next/dist/server/require-hook.js:65:28)
[22:31:42.744] at require (node:internal/modules/helpers:177:18)
[22:31:42.744] at Object. (/vercel/path0/node_modules/next/node_modules/sharp/lib/constructor.js:10:1)
[22:31:42.744] at Module._compile (node:internal/modules/cjs/loader:1364:14)
[22:31:42.744]
[22:31:42.744] Import trace for requested module:
[22:31:42.744] ./public/images/logo/sin-fronteras.png
[22:31:42.744]
[22:31:42.744]
[22:31:42.744] > Build failed because of webpack errors
[22:31:42.825] Error: Command “npm run build” exited with 1
[22:31:44.208]

The logs show the following, have you tried installing sharp manually into your project?

Hi Christian,
Thank you for the help.
I have already tried what the logs say.
switched to node 18 (I was running 20 before) and
I ran locally:

  • npm install --os=linux --cpu=x64 sharp
  • npm install --include=optional sharp
    There was no change to my package.json… I made some change in some file and commited again,

locally the build succeeded but on deoloy to vercel it fails…

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